gpt4 book ai didi

kotlin - 如何结合JUnit4 @RunWith(Parameterized.class)和JUnit5 @ParameterizedTest

转载 作者:行者123 更新时间:2023-12-02 12:53:42 26 4
gpt4 key购买 nike

我试图将来自JUnit4的参数化运行器的概念与JUnit5参数化测试结合起来。本质上,我想在同一组数据上测试两个单独的函数。

我知道我可以将函数作为另一个参数添加到参数化测试本身,但是我试图使更改或添加新功能变得容易。

我是否可以利用嵌套的测试类来实现这一目标?我不确定最好的方法。

@RunWith(Parameterized::class)
class RomanNumeralTest(val func: (Int) -> String) {

@ParameterizedTest(name = "{index} - Expect [{0}] should return [{1}]")
@MethodSource("testData")
fun `Test roman numeral from integer values`(num: Int, expected: String) =
assertEquals(expected, func(num))

companion object {

@JvmStatic
@Parameterized.Parameters
fun data(): Collection<Array<(Int) -> String>> {
return listOf(
arrayOf({num -> roman(num)}),
arrayOf({num -> num.toRomanNumeral()})
)
}

@JvmStatic
private fun testData() = sequenceOf(
arrayOf(1, "I"),
arrayOf(2, "II"),
arrayOf(3, "III"),
arrayOf(4, "IV"),
arrayOf(5, "V")
).asStream()
}
}

最佳答案

I tried the same but in the end I came to the conclusion that: you can't.



您无法通过JUnit 5附带的注释来使用JUnit 4 Parameterized测试运行程序。

您需要转到JUnit 5才能使用最新功能,例如 TestFactoryhere中描述的参数化测试的所有强大注释。

关于kotlin - 如何结合JUnit4 @RunWith(Parameterized.class)和JUnit5 @ParameterizedTest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54797139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com