コマンドラインから引数を受け取る、3 つのパラメーター化されたメソッドを含むプログラムがあります。それらをテストしたいので、元のクラスを右クリックして新しいJUnitテストをクリックして、JUnitでテストを作成しました。テスト クラスでは、クラスに as @RunWith(Parameterized.class)
、パラメーター化されたメソッドに as @Parameters
、testmain
メソッドに as という注釈を付けました@test
。
各メソッドで、元のクラスの参照を作成し、メソッドを呼び出して必要なパラメーターを渡しました。ここで、テスト クラスにパブリックな静的メソッドがないことを示す初期化エラーが発生します。これがテストを実行するための正しい方法であるかどうか、誰かが私にアドバイスできますか?そうでない場合は、それを行う正しい方法は何ですか.
自分自身を明確にするために、これまでに行ったことの例も示します (これは元のコードではありません)。
@RunWith(Parameterized.class)
Public class customertest(){
@Parameters
public testmethod1(String a, String b){
customer test = new customer();
test.method1(a, b);
}
@Parameters
public testmethod2(String c, String d){
customer test = new customer();
test.method2(c, d);
}
@parameters
public testmethod3(String e){
customer test = new customer();
test.method3(e);
}
@Test
public static void testmain(String [] args){
customertest tester = new customertest();
tester.testmethod1(args[0], args[1]);
tester.testmethod2(args[2], args[3]);
tester.testmethod3(args[4]);
}
}