[java] junit thread testing.

ITWeb/개발일반 2013. 4. 8. 12:51

메인 class 에 multi thread 로 구현된 코드를 junit test 로 테스트 할려고 할때 복잡 하지 않고 단순 테스트용 도로만 그냥 돌리고 싶다면 test code 에 sleep(적당한 시간) 을 주면 테스트 가능 합니다.


그냥 돌리게 되면 test 수행이 끝남과 동시에 thread 는 종료가 되어서 실제 thread 내부 코드가 잘 동작 하는지 확인이 안됩니다.


아래는 그냥 테스트 한 코드이니 참고 정도만 하세요.


@Test

public void testClientIndexer() throws Exception {

    ClientIndexer clientIndexer ;


    clientIndexer = new ClientIndexer();

    clientIndexer.connect();

    clientIndexer.open();


    Thread.sleep(30000);

}


: