使用Junit 5 Jupiter运行JBehave

时间:2018-05-19 17:05:05

标签: java junit jbehave

我正在尝试在JUnit 5上运行一些基于JUnit 4的JBehave测试。在我的项目中,我有一个针对所有故事JBehaveTest的测试类。

当我作为JUnit 5测试运行时,JUnit没有看到任何测试。我将@Test注释修改为它们的Jupiter等价物,我将assertTrueassertFalse更改为它们的等价物等。

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'

0 个答案:

没有答案