프로그래밍/Java
[junit] 멀티스레드 테스트
galad
2010. 9. 27. 11:40
참조: http://devyongsik.tistory.com/263
http://today.java.net/pub/a/today/2003/08/06/multithreadedTests.html
보통은 스레드가 다 돌기 전에 junit 테스트가 끝나버림.
groboutils 이라는 라이브러리 사용해서 멀티스레드 테스트 가능.
위와 같이 하면 된다는데, 길고 복잡해서 그냥 스레드 돌리고 밑에다가 sleep 줘버렸음 ㅡ.ㅡ;;;
http://today.java.net/pub/a/today/2003/08/06/multithreadedTests.html
보통은 스레드가 다 돌기 전에 junit 테스트가 끝나버림.
groboutils 이라는 라이브러리 사용해서 멀티스레드 테스트 가능.
public class Tester extends TestRunnable { //net.sourceforge.groboutils.junit.v1.TestRunnable를 상속 private Log logger = LogFactory.getLog(Tester.class); int i = 0; public Tester(int i ) { this.i = i; } @Override public void runTest() { //net.sourceforge.groboutils.junit.v1.TestRunnable의 runTest메서드를 오버라이드 //이 메서드는 Runnable의 run 메서드가 해야 할 일이 들어갑니다. try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(Thread.currentThread().getName() + " : [" + i + "]"); } } public class TestThread extends TestCase { private Log logger = LogFactory.getLog(TestThread.class); @Test public void testM() throws Throwable { TestRunnable[] t = new TestRunnable[20]; //TestRunnable로 배열을 만들고 for(int index = 0; index < 20; index++) { t[index] = new Tester(index); //TestRunnable을 상속한 Runnable의 run 메서드를 테스트 할 클래스를 넣습니다. } MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(t); //이렇게 생성하고 mttr.runTestRunnables(); //이렇게 테스트 합니다. System.out.println("main end........................."); } } |
위와 같이 하면 된다는데, 길고 복잡해서 그냥 스레드 돌리고 밑에다가 sleep 줘버렸음 ㅡ.ㅡ;;;