gpt4 book ai didi

java - JUnit 测试方法可以有参数吗?

转载 作者:IT老高 更新时间:2023-10-28 20:53:50 32 4
gpt4 key购买 nike

import java.util.regex.Pattern;

public class TestUI {
private static Pattern p = Pattern.compile("^[A-Za-z0-9()+-]+$");

public static void main(String[] args) {
// Test case1
String[] str=test();

System.out.println(str[0]+str.length);
match("Alphanumeric(Text)");
}

private static String[] test() {

boolean res;
String[] array={"a","b","c","d","e"};
for(int i=0;i<array.length;i++){
System.out.println(match(array[i]));
res=match(array[i]);
if(res=true)
calltomethod(array);
}

return array;
}

private static boolean match(String s) {
return p.matcher(s).matches();
}

}

在上面的代码中,我需要将数组作为参数传递给 JUnit 方法,上面的代码将出现在 JUnit 类中,我可以在 JUnit 类中使用这些方法和带有参数的 test =method ?

最佳答案

您应该看看参数化单元测试(在 JUnit 4 中引入)。

Daniel Mayer's blog有一个例子。

另一个更简单的例子是 mkyong's webpage

关于java - JUnit 测试方法可以有参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7234339/

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