我正在尝试在JUnit 5木星中运行黄瓜功能。我已经从Cucumber-jvm源代码中提取了一些代码,并将其改编为JUnit 5的TestFactory
。它的工作:我看到我的功能运行时,我运行所有的JUnit测试(这是科特林代码,但同样适用于Java的):如何获得黄瓜功能的结果
@CucumberOptions(
plugin = arrayOf("pretty"),
features = arrayOf("classpath:features")
)
class Behaviours {
@TestFactory
fun loadCucumberTests() : Collection<DynamicTest> {
val options = RuntimeOptionsFactory(Behaviours::class.java).create()
val classLoader = Behaviours::class.java.classLoader
val resourceLoader = MultiLoader(classLoader)
val classFinder = ResourceLoaderClassFinder(resourceLoader, classLoader)
val runtime = Runtime(resourceLoader, classFinder, classLoader, options)
val cucumberFeatures = options.cucumberFeatures(resourceLoader)
return cucumberFeatures.map<CucumberFeature, DynamicTest> { feature ->
dynamicTest(feature.gherkinFeature.name) {
var reporter = options.reporter(classLoader)
feature.run(options.formatter(classLoader), reporter, runtime)
}
}
}
}
然而,JUnit的报告说,每一个功能是成功的,它是否实际上是。功能失败时,结果将正确打印,但会生成DynamicTest
。 gradle test
和Intellij都没有注意到这个错误:我必须检查文本输出。
我想我必须弄清楚,在Executable
作为第二个参数传递给dynamicTest
时,该功能的结果是什么,并在适当的时候提出断言。我该如何确定feature
或feature.gherkinFeature
的结果?
是否有一种方法可以获取功能中每个场景的结果?或者更好的是,有没有办法运行特定的场景,以便我可以为每个场景创建一个DynamicTest,为JUnit提供更好的报告粒度?
您可以使用挂接之后,脚本对象传递给它。场景类具有getStatus(),它返回传递,失败,未定义,跳过,挂起或返回布尔值的isFailed()。 – Grasshopper
也许[这个问题](https://stackoverflow.com/questions/35550386/cucumber-jvm-hooks-when-scenario-is-passed-or-failed/35553304#35553304)可以帮助你。 – troig
你的例子中记者是什么类型的?我还没有深入研究过Junit5,但是对于junit4集成,这应该是一个'JunitReporter',它将信息转发给junit'RunNotifier'。 –