私の問題は、次のようなマルチスレッドの方法でメソッドを呼び出す必要があることです
@Test
public void assignInMutiThread()
{
Thread thread1 = new Thread(new AssignAndExpect(0));
thread1.start();
Thread thread2 = new Thread(new AssignAndExpect(1));
thread2.start();
thread1.join();
thread2.join();
}
スレッドは http 要求を送信し、応答が期待どおりかどうかを確認します。メソッドをオーバーライドする必要があるpublic void run()
ため、テスト メソッドに応答コードを返すことができません。
public class AssignExecuteAndAssert implements Runnable{
int expectedAssert = 0;
public AssignExecuteAndAssert(int expectedAssert)
{
this.expectedAssert = expectedAssert;
}
public void run() {
HttpGet assign1 = new HttpGet("http://localhost:8707/assign?uuid="+(new Random().nextInt(99999)));
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(assign1);
InputStream inputStream = response.getEntity().getContent();
int resoponseStatus = inputStream.read();
Assert.assertEquals(resoponseStatus, expectedAssert);
}
}
問題は、Assert が正しいか間違っているかに関係なく、このテスト メソッドは常に渡されます。スレッドのアサートが失敗した場合にテストを失敗させる方法はありますか?
ここで同様の質問を見つけます: Failing TestNG unit test from a callback I don't own in my code but there's no answer.
そして、提案をいただければ幸いです。
ありがとう!