[英]JUnit 5 - Parameterized test default display name with @CsvSource when the parameter is an user defined class
I have a parameterized test that uses an user defined class as the parameter,我有一个参数化测试,它使用用户定义的 class 作为参数,
@ParameterizedTest
@CsvSource({ "1 a", "2 b" })
@Order(8)
void csvSourceIntString(IntString is) {
}
IntString
is define as follows, notice that I defined toString
: IntString
定义如下,注意我定义了toString
:
import java.util.Scanner;
class IntString {
int i;
String s;
public IntString(int i, String s) {
this.i = i;
this.s = s;
}
public IntString(String is) {
try (Scanner scanner = new Scanner(is)) {
i = scanner.nextInt();
s = scanner.next();
}
}
@Override
public String toString() {
return "i=" + i + ",s=" + s;
}
}
I was expecting the default display names of the tests to be我期待测试的默认显示名称是
[1] i=1,s=a
[2] i=2,s=b
Instead, when I ran this in Eclipse, they are what is in @CsvSource
相反,当我在 Eclipse 中运行它时,它们就是@CsvSource
中的内容
[1] 1 a
[2] 2 b
Is this expected?这是预期的吗?
BTW, @MethodSource
gave me expected default display names.顺便说一句, @MethodSource
给了我预期的默认显示名称。
You could try to set the name of the parameterized test explicitely:您可以尝试明确设置参数化测试的名称:
@ParameterizedTest(name = "[{index}] {0}")
@CsvSource({ "1 a", "2 b" })
@Order(8)
void csvSourceIntString(IntString is) {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.