一緒にグループのJUnitテストにjunit API:どのように私は一緒にグループ使用して、共通のテスト意志のJUnitランナーを作成しようとしてい
package whatever;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
public class SomeTestRunner extends Runner {
public SomeTestRunner(Class<?> testClass) {}
@Override
public Description getDescription() {
return Description.EMPTY;
}
@Override
public void run(RunNotifier notifier) {
for (int i = 0; i < 3; i++) {
Description parent = Description.createSuiteDescription("Parent_" + i);
for (int j = 0; j < 3; j++) {
Description child = Description.createTestDescription(Exception.class, "Child_" + j);
parent.addChild(child);
Failure failure = new Failure(child, new Exception());
notifier.fireTestFailure(failure);
}
Failure failure = new Failure(parent, new Exception());
notifier.fireTestFailure(failure);
}
}
}
私はこのランナーを使用してテストを実行すると、問題は、私ができる、です行の失敗、両親と子供たちを見るのではなく、一緒にグループ化された:
Results :
Tests in error:
Child_0(java.lang.Exception)
Child_1(java.lang.Exception)
Child_2(java.lang.Exception)
Parent_0
Child_0(java.lang.Exception)
Child_1(java.lang.Exception)
Child_2(java.lang.Exception)
Parent_1
Child_0(java.lang.Exception)
Child_1(java.lang.Exception)
Child_2(java.lang.Exception)
Parent_2
Tests run: 12, Failures: 0, Errors: 12, Skipped: 0
はまた、私はEclipseでこのテストを実行するときにそれらを一緒にグループ化が見込ま - しかしケースはないthatsの。私は何が欠けていますか?それも可能ですか?
テストの失敗を起こすのと同じ順序で印刷されます。あなたは何を期待していましたか? – Perception
私はそれらをスイートで一緒にグループ化することを期待しました。それはcreateSuiteDescription()とaddChild()が何をするためのものなのでしょうか? – uzilan