[英]how to change csvparsersettings of junit parameterized tests using @csvsource
[英]JUnit 5 - Parameterized test default display name with @CsvSource when the parameter is an user defined class
我有一個參數化測試,它使用用戶定義的 class 作為參數,
@ParameterizedTest
@CsvSource({ "1 a", "2 b" })
@Order(8)
void csvSourceIntString(IntString is) {
}
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;
}
}
我期待測試的默認顯示名稱是
[1] i=1,s=a
[2] i=2,s=b
相反,當我在 Eclipse 中運行它時,它們就是@CsvSource
中的內容
[1] 1 a
[2] 2 b
這是預期的嗎?
順便說一句, @MethodSource
給了我預期的默認顯示名稱。
您可以嘗試明確設置參數化測試的名稱:
@ParameterizedTest(name = "[{index}] {0}")
@CsvSource({ "1 a", "2 b" })
@Order(8)
void csvSourceIntString(IntString is) {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.