Created
November 30, 2012 07:17
-
-
Save need4spd/4174273 to your computer and use it in GitHub Desktop.
MultiThreaded Test with Junit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Tester implements Runnable { | |
private Log logger = LogFactory.getLog(Tester.class); | |
int i = 0; | |
public Tester(int i ) { | |
this.i = i; | |
} | |
public void 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() { | |
for(int index = 0; index < 20; index++) { | |
new Thread(new Tester(index)).start(); | |
} | |
System.out.println("main end........................."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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........................."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestThread extends TestCase { | |
public class TesterInner extends TestRunnable { | |
int i = 0; | |
public TesterInner(int i ) { | |
this.i = i; | |
} | |
@Override | |
public void runTest() { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
System.out.println(Thread.currentThread().getName() + " : [" + i + "]"); | |
} | |
} | |
@Test | |
public void testM() throws Throwable { | |
TestRunnable[] t = new TestRunnable[20]; | |
for(int index = 0; index < 20; index++) { | |
t[index] = new TesterInner(index); | |
} | |
MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(t); | |
mttr.runTestRunnables(); | |
System.out.println("main end........................."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment