Junit 5:如何为参数化测试提供名称
Junit 5 : How to provide names to Parameterized Test
我有如下简单的参数化测试用例
@ParameterizedTest
@ValueSource(strings = { "Hello", "World","Test" })
void withFixValues(String word) {
System.out.println(word);
assertNotNull(word);
}
但万一测试失败,要检查哪个参数值测试失败并不容易。有什么办法可以根据参数命名参数化测试用例?
我们可以使用名称属性提供名称。
@ParameterizedTest(name = "withSomeName #{index} with Value [{arguments}]")
@ValueSource(strings = { "Hello", "World","Test" })
void withFixValues(String word) {
System.out.println(word);
assertNotNull(word);
}
我有如下简单的参数化测试用例
@ParameterizedTest
@ValueSource(strings = { "Hello", "World","Test" })
void withFixValues(String word) {
System.out.println(word);
assertNotNull(word);
}
但万一测试失败,要检查哪个参数值测试失败并不容易。有什么办法可以根据参数命名参数化测试用例?
我们可以使用名称属性提供名称。
@ParameterizedTest(name = "withSomeName #{index} with Value [{arguments}]")
@ValueSource(strings = { "Hello", "World","Test" })
void withFixValues(String word) {
System.out.println(word);
assertNotNull(word);
}