0

スレッドからスローされた RunTimeException が System.err に追加されているかどうかをテストしようとしています。しかし、1分間待ってもSystem.errに見つかりません。以下はコード部分です

public class TestTest {
  @Rule public SystemErrRule errRule = new SystemErrRule().enableLog();

  @org.junit.Test
  public void testLogging(){
    ExecutorRunner.submitTask(new Runnable() {
      @Override public void run() {
        throw new RuntimeException("exception");
      }
    });

Awaitility.await().atMost(60l, TimeUnit.SECONDS).until(new Callable<Boolean>() {
  @Override public Boolean call() throws Exception {
    return errRule.getLog().contains("exception");
  }
});

System.out.println("TestTest.testLogging :: " + "errLog: "+errRule.getLog());
assertTrue(errRule.getLog().contains("exception"));


}

  @After
  public void checkException(){
    System.out.println("TestTest.checkException :: " + "checkin log");
  }

}

class ExecutorRunner{
  static final ExecutorService execService = Executors
    .newCachedThreadPool(new ThreadFactory() {
      AtomicInteger threadNum = new AtomicInteger();

      public Thread newThread(final Runnable r) {
        Thread result = new Thread(r, "Function Execution Thread-"
          + threadNum.incrementAndGet());
        result.setDaemon(true);
        return result;
      }
    });

  static void submitTask(Runnable task) {
    execService.submit(task);
  }
}

誰かがテストで間違いの可能性を指摘できますか?

4

1 に答える 1