我正在尝试在JUnit 5上运行一些基于JUnit 4的JBehave测试。在我的项目中,我有一个针对所有故事JBehaveTest
的测试类。
当我作为JUnit 5测试运行时,JUnit没有看到任何测试。我将@Test
注释修改为它们的Jupiter等价物,我将assertTrue
和assertFalse
更改为它们的等价物等。
JUnit 4测试使用@RunWith
注释进行注释,如果我理解正确的话,在JUnit 5中应该是@ExtendWith
注释。不幸的是JBehave
不是JUnit 5扩展,所以它不会编译。
JBe可以和JUnit 5一起使用,如果是的话,怎么用?
@RunWith(AnnotatedEmbedderRunner.class)
@UsingEmbedder(embedder = Embedder.class, verboseFailures = true, ignoreFailureInStories = false, generateViewAfterStories = true)
public class JBehaveTest implements Embeddable {
private Embedder embedder;
private DotStoryReporter dot = new DotStoryReporter();
private Stage primaryStage;
@Before
public void createStage() throws TimeoutException {
Locale locale = new Locale("fa", "IR");
Locale.setDefault(locale);
primaryStage = FxToolkit.registerPrimaryStage();
}
@Override
@Test
public void run() throws Throwable {
embedder.runStoriesAsPaths(new StoryFinder().findPaths("src/test/resources", Collections.singletonList("**/*.story"), Collections.<String>emptyList()));
}
@Override
public void useEmbedder(Embedder embedder) {
this.embedder = embedder;
MostUsefulConfiguration configuration = new MostUsefulConfiguration();
Steps steps = new Steps();
configuration.useStoryReporterBuilder(
new StoryReporterBuilder()
.withCodeLocation(CodeLocations.codeLocationFromClass(JBehaveTest.class))
.withDefaultFormats()
.withReporters(dot, new MyStoryReporter(new File("test"), steps))
.withFormats(Format.HTML, Format.TXT)
.withFailureTrace(true)
.withFailureTraceCompression(false));
configuration.useStepdocReporter(new DetailedStepReporter());
embedder.useStepsFactory(new InstanceStepsFactory(configuration, steps));
embedder.useConfiguration(configuration);
}
Gradle测试依赖项是:
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testCompile 'org.mockito:mockito-core:2.18.3'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
testRuntime 'org.junit.platform:junit-platform-launcher:1.2.0'
testCompile 'org.testfx:testfx-core:4.0.+'
testCompile 'org.testfx:testfx-junit5:4.0.+'
testCompile 'org.jbehave:jbehave-core:4.3.2'
testCompile 'de.codecentric:jbehave-junit-runner:1.2.0'