AssertJ JUnitSoftAssertions 和 Guava 断言

AssertJ JUnitSoftAssertions and Guava assertions

我沉迷于 AssertJ JUnit 规则 JUnitSoftAssertions。这真的很方便,你只需将它添加为测试 class 字段

@Rule
public JUnitSoftAssertions softy = new JUnitSoftAssertions();

然后你在上面链接了几个 assertThat

现在,我添加了 Guava assertions from AssertJ 的依赖项,但在我看来,没有规则或无法在 JUnit 规则中注册新断言。因此我必须使用丑陋的静态导入。

我错了吗?如果是,请说明如何在 JUnit 规则中使用它们(无需我自己实现。

目前 assertj-guava 中没有软断言支持,但添加它并不难,只需要一个 class,例如:

/**
 * A single entry point for all soft assertions, AssertJ standard assertions and MyProject custom assertions.
 */
// extending make all standard AssertJ assertions available
public class GuavaJUnitSoftAssertions extends JUnitSoftAssertions {

  public <K, V> MultimapAssert<K, V> assertThat(final Multimap<K, V> actual) {
    return proxy(MultimapAssert.class, Multimap.class, actual);
  }

  // add the other guava assertThat methods 
  // ... 
}

很高兴为此做出贡献(我现在有点忙)。

希望对您有所帮助