ファイルからデータを読み取り、そのデータを使用してプロシージャをテストしようとしています。テストする 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
以下のプログラムは、ファイルを読み取り、その内容を 2 次元の String 配列に入力しようとします。
@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 は、データベースに接続して、実際の値が期待される結果と一致するかどうかを確認するメソッドです。これは、2 つの文字列値を引数として取ります。
私の質問は、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;
}
これを機能させるためのアドバイスはありますか?