@Test
public void testParallelInvocations()
throws Exception
{
final MockReporter reporter = new MockReporter();
final RunListener jUnit4TestSetReporter = new JUnit4RunListener( reporter );
final CountDownLatch countDownLatch = new CountDownLatch( 1 );
final Description testSomething = Description.createTestDescription( STest1.class, "testSomething" );
final Description testSomething2 = Description.createTestDescription( STest2.class, "testSomething2" );
jUnit4TestSetReporter.testStarted( testSomething );
new Thread( new Runnable()
{
public void run()
{
try
{
jUnit4TestSetReporter.testStarted( testSomething2 );
jUnit4TestSetReporter.testFailure( new Failure( testSomething2, new AssertionError( "Fud" ) ) );
jUnit4TestSetReporter.testFinished( testSomething2 );
countDownLatch.countDown();
}
catch ( Exception e )
{
throw new RuntimeException( e );
}
}
} ).start();
countDownLatch.await();
jUnit4TestSetReporter.testFinished( testSomething );
Assert.assertEquals( "Failing tests", 1, reporter.getTestFailed() );
Assert.assertEquals( "Succeeded tests", 1, reporter.getTestSucceeded() );
}