blob: c4890d037c0384ae90a283fe692ad0409f1ae6ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package org.junit.tests.junit3compatibility;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import junit.framework.JUnit4TestAdapter;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
import org.junit.runner.Result;
public class SuiteMethodTest {
public static boolean wasRun;
static public class OldTest extends TestCase {
public OldTest(String name) {
super(name);
}
public static junit.framework.Test suite() {
TestSuite result= new TestSuite();
result.addTest(new OldTest("notObviouslyATest"));
return result;
}
public void notObviouslyATest() {
wasRun= true;
}
}
@Test public void makeSureSuiteIsCalled() {
wasRun= false;
JUnitCore.runClasses(OldTest.class);
assertTrue(wasRun);
}
static public class NewTest {
@Test public void sample() {
wasRun= true;
}
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(NewTest.class);
}
}
@Test public void makeSureSuiteWorksWithJUnit4Classes() {
wasRun= false;
JUnitCore.runClasses(NewTest.class);
assertTrue(wasRun);
}
public static class CompatibilityTest {
@Ignore @Test
public void ignored() {
}
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(CompatibilityTest.class);
}
}
// when executing as JUnit 3, ignored tests are stripped out before execution
@Test
public void descriptionAndRunNotificationsAreConsistent() {
Result result= JUnitCore.runClasses(CompatibilityTest.class);
assertEquals(0, result.getIgnoreCount());
Description description= Request.aClass(CompatibilityTest.class).getRunner().getDescription();
assertEquals(0, description.getChildren().size());
}
static public class NewTestSuiteFails {
@Test public void sample() {
wasRun= true;
}
public static junit.framework.Test suite() {
fail("called with JUnit 4 runner");
return null;
}
}
@Test public void suiteIsUsedWithJUnit4Classes() {
wasRun= false;
Result result= JUnitCore.runClasses(NewTestSuiteFails.class);
assertEquals(1, result.getFailureCount());
assertFalse(wasRun);
}
static public class NewTestSuiteNotUsed {
private static boolean wasIgnoredRun;
@Test public void sample() {
wasRun= true;
}
@Ignore @Test public void ignore() {
wasIgnoredRun= true;
}
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(NewTestSuiteNotUsed.class);
}
}
@Test public void makeSureSuiteNotUsedWithJUnit4Classes2() {
wasRun= false;
NewTestSuiteNotUsed.wasIgnoredRun= false;
Result res= JUnitCore.runClasses(NewTestSuiteNotUsed.class);
assertTrue(wasRun);
assertFalse(NewTestSuiteNotUsed.wasIgnoredRun);
assertEquals(0, res.getFailureCount());
assertEquals(1, res.getRunCount());
assertEquals(0, res.getIgnoreCount());
}
}
|