我正在尝试在JUnit 5上运行一些基于JUnit 4的JBehave测试。在我的项目中,我有一个针对所有故事的测试类
JBehaveTest
.
@Test
对它们的木星等价物的注释,我更改了
assertTrue
assertFalse
对他们的等价物等。
JUnit4测试用
@RunWith
注释,在JUnit 5中应该是
@ExtendWith
如果我理解正确的话。不幸的是
JBehave
不是JUnit5扩展,因此不会编译。
JBehave可以与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);
}
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'