我有这样的方法,
public void beforeTest(String a, String b, String c, String d) {
x = getURL(a, b, c, d);
--------
--------
}
我现在想传递 String[] 而不是单个字符串作为参数类型,所以尝试了这个,
public void beforeTest(String[] args){
x = getURL(a, b, c, d);
--------
--------
}
并传递 a、b、c、d 作为命令行参数,我的代码无法正常工作,这是正确的方法吗?
谢谢大家,我确实尝试了 getURL(args[0].......) 方法,不幸的是我仍然遇到同样的错误,
[testng]配置失败:@BeforeMethod beforeTest [testng] org.testng.TestNGException:[testng]方法 beforeTest 需要 1 个参数,但 @Configuration 注释中提供了 4 个参数。
顺便说一句,我的 getURL 方法定义如下,
protected String getURL(String a, String b, String c, String d) {
if (condition){
return a
} else if (condition) {
return b
} ....
最佳答案
试试这个。
String a = args[0];
String b = args[1];
String c = args[2];
String d = args[3];
将 4 个字符串作为命令行参数传递是可以的。
关于java - Java 中的字符串到 String[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20531482/