我正在尝试从文件中读取数据并使用这些数据来测试 procs。甚至要测试的 proc 也是根据文件的内容确定的。
Sample.txt 是我从中读取数据的文件,该文件包含以下数据
testproc=sample_check('N')
output=yes
type=function
testproc=sample_check('N')
output=yes
type=function
testproc=sample_check('N')
output=yes
type=function
下面的程序尝试读取文件并将其内容填充到二维字符串数组中。
@RunWith(value = Parameterized.class)
public class Testdata extends Testdb {
public String expected;
public String actual;
@Parameters
public static Collection<String[]> getTestParameters() {
String param[][] = new String [3][3];
String temp[] = new String [3];
int i = 0;
int j = 0;
try{
BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
String strLine;
String methodkey = "testproc";
String methodtypekey = "type";
String methodoutputkey = "output";
String method = "";
String methodtype = "";
String methodoutput = "";
//Read File Line By Line
while ((strLine = br.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(strLine, "=");
while(st.hasMoreTokens())
{
String key = st.nextToken();
String val = st.nextToken();
if (key.trim().equalsIgnoreCase(methodkey))
{
method = val.trim();
temp[j] = "SELECT " + method + " FROM dual";
j++;
}
else if (key.trim().equalsIgnoreCase(methodoutputkey))
{
methodoutput = val.trim();
temp[j] = methodoutput;
j++;
}
else if (key.trim().equalsIgnoreCase(methodtypekey))
{
methodtype = val.trim();
if (methodtype.trim().equalsIgnoreCase("function"))
{
System.out.println(i + " " + method);
param[i] = temp;
i++;
j = 0;
}
}
}
}
}
catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
return Arrays.asList(param) ;
}
public Testdata(String[] par) {
this.expected = par[0];
this.actual = par[1];
}
@Test
public void test_file_data() //throws java.io.IOException
{
testString("Output should be"+expected , expected, actual);
}
}
我收到一个错误 java.lang.IllegalArgumentException: wrong number of arguments
testString 是一种连接数据库以检查实际值是否与预期结果相符的方法。这需要两个字符串值作为参数。
我的问题是 return Arrays.asList(param) 和方法 public Testdata(String[] par) 应该如何?
我使用它进行了测试,它工作正常,但由于我从文件中读取,我想使用一个需要使用 return Arrays.asList 返回的数组
return Arrays.asList(new String[][]{
{ "yes", "SELECT sample_check('N') FROM dual"},
{ "yes", "SELECT sample_check('N') FROM dual"},
{ "yes", "SELECT sample_check('N') FROM dual"}
}) ;
}
public Testdata(String expected,
String actual) {
this.expected = expected;
this.actual = actual;
}
关于让它工作的任何建议?