forked from junit-team/junit4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes junit-team#1189: JUnit4TestAdapter blocks JUnit-3-style suites …
…that are included via @RunWith(Suite.class)
- Loading branch information
Showing
4 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
82 changes: 82 additions & 0 deletions
82
src/test/java/org/junit/tests/junit3compatibility/JUnit4TestAdapterTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.junit.tests.junit3compatibility; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Collections; | ||
|
||
import junit.framework.JUnit4TestAdapter; | ||
import junit.framework.TestCase; | ||
import junit.framework.TestResult; | ||
import junit.framework.TestSuite; | ||
import org.junit.Test; | ||
import org.junit.runner.JUnitCore; | ||
import org.junit.runner.Result; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Suite; | ||
|
||
public class JUnit4TestAdapterTest { | ||
|
||
private static void doTest(Class<?> clazz) { | ||
// JUnit 4 runner: | ||
Result result = JUnitCore.runClasses(clazz); | ||
assertEquals(1, result.getRunCount()); | ||
assertEquals(0, result.getFailureCount()); | ||
assertEquals(0, result.getIgnoreCount()); | ||
|
||
// JUnit 3 runner: | ||
TestResult testResult = new TestResult(); | ||
new JUnit4TestAdapter(clazz).run(testResult); | ||
assertEquals(1, testResult.runCount()); | ||
assertEquals(0, testResult.failureCount()); | ||
assertEquals(Collections.emptyList(), Collections.list(testResult.errors())); | ||
} | ||
|
||
public static class Test4 { | ||
@Test | ||
public void pass() throws Exception { | ||
//pass | ||
} | ||
} | ||
|
||
@RunWith(Suite.class) | ||
@Suite.SuiteClasses(Test4.class) | ||
public static class TestSuiteFor4 { | ||
} | ||
|
||
@Test | ||
public void testJUnit4Suite() { | ||
doTest(TestSuiteFor4.class); | ||
} | ||
|
||
public static class Test3 extends TestCase { | ||
public void testPass() throws Exception { | ||
//pass | ||
} | ||
} | ||
|
||
@RunWith(Suite.class) | ||
@Suite.SuiteClasses(Test3.class) | ||
public static class TestSuiteFor3 { | ||
} | ||
|
||
@Test | ||
public void testJUnit3Suite() { | ||
doTest(TestSuiteFor3.class); | ||
} | ||
|
||
public static class TestSuite3 { | ||
public static junit.framework.Test suite() { | ||
return new TestSuite(Test3.class); | ||
} | ||
} | ||
|
||
@RunWith(Suite.class) | ||
@Suite.SuiteClasses(TestSuite3.class) | ||
public static class TestSuite4ForTestSuite3 { | ||
} | ||
|
||
@Test | ||
public void testJUnit4SuiteThatContainsJUnit3SuiteClass() { | ||
doTest(TestSuite4ForTestSuite3.class); | ||
} | ||
} |