我面临同样的问题,经过一些谷歌工作后,我得到了解决方案:
@RunWith(ParameterizedRobolectricTestRunner::class)
@CucumberOptions( features = ["src/test/features/test.feature","src/test/features/others.feature"], plugin = ["pretty"])
class RunFeatures(val index: Int, val name:String) {
companion object {
@Parameters(name = "{1}")
@JvmStatic
fun features(): Collection<Array<Any>> {
val runner = Cucumber(RunFeatures::class.java)
Cucumber()
val children = runner.children
return children.mapIndexed{index, feature ->
arrayOf(index,feature.name)
}
}
}
@Test
fun runTest() {
val core = JUnitCore()
val feature = Cucumber(RunFeatures::class.java).children[index]!!
core.addListener(object: RunListener() {
override fun testFailure(failure: Failure?) {
super.testFailure(failure)
fail("$name failed:\n"+failure?.exception)
}
})
val runner = Request.runner(feature)
core.run(runner)
}
}
但对我来说似乎不是一个很好的解决方案,有人可以帮我解决这些问题:
- 必须明确列出所有功能文件路径。但不能使用 *.feature 等模式
- 失败时无法知道哪一步失败。
- 参数只能传递原始类型数据,
我已经进入黄瓜源,但似乎 CucumberOptions 内联黄瓜,我不能以编程方式传递它,但只能使用注释。