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();
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我需要将数组作为参数传递给JUnit方法,上面的代码将出现在JUnit类中,我可以在JUnit类中使用这些方法,使用带参数的test =方法吗?
是的,您可以使用TheoriesJUnit 4.4中的Runner
@RunWith(Theories.class)
public class TheorieTest {
@DataPoints
public static String[] strings={"a","b","c","d","e"};
private static Pattern p = Pattern.compile("^[A-Za-z0-9()+-]+$");
@Theory
public void stringTest(String x) {
assertTrue("string " + x + " should match but does not", p.matcher(x).matches());
}
}
Run Code Online (Sandbox Code Playgroud)
更多细节:
是的,它可以。最近我开始了zohhak项目。它让你写:
@TestWith({
"25 USD",
"38 GBP",
"null"
})
public void testMethod(Money money) {
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27947 次 |
| 最近记录: |