純粋なJUnitソリューションの場合は、ErrorCollector TestRuleを使用してアサーションを処理します。
ErrorCollectorテストの実行が完了するまで、ルールは報告しません。
あなたの具体的な例では
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNull;
import org.hamcrest.text.IsEmptyString;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
public class ErrorCollectorTest {
@Rule
public ErrorCollector collector = new ErrorCollector();
@Test
public void testMultiAssertFailure() {
collector.checkThat(true, IsEqual.equalTo(false));
collector.checkThat("notEmpty", IsEmptyString.isEmptyString());
collector.checkThat(new Object(), IsNull.nullValue());
collector.checkThat(null, IsNull.notNullValue());
try {
throw new RuntimeException("Exception");
} catch (Exception ex){
collector.addError(ex);
}
}
}
:
assertTrue("string on failure",condition1);
assertTrue("string on failure",condition2);
assertTrue("string on failure",condition3);
assertTrue("string on failure",condition4);
assertTrue("string on failure",condition5);
は、ここで他のオプションは、多くの人々はとにかく常にやるべきことを言うことがベストプラクティスです
Matcher<Boolean> matchesTrue = IsEqual.equalTo(true);
collector.checkThat("String on Failure", condition1, matchesTrue);
collector.checkThat("String on Failure", condition2, matchesTrue);
collector.checkThat("String on Failure", condition3, matchesTrue);
collector.checkThat("String on Failure", condition4, matchesTrue);
collector.checkThat("String on Failure", condition5, matchesTrue);
しかしこれはJunitに当てはまります....私はこれがtestngのものだと思った –
AssertJはJUnitを依存関係として持っています(https://mvnrepository.com/artifact/org.assertj/assertj-core/3.5.1)ので、うまくいくはずです例外を収集し、ただちにすべてを吐き出すだけです。そのコンセプトは、単なる単体テストのフレームワークや言語と結びついていません。実際、Pythonでのソフトアサーション(http://pythontesting.net/strategy/delayed-assert)の実装は、@jeremiahが提案したものとまったく同じです。 – pr4bh4sh