blob: 1df01671cbb1e055cc2a9b6da168a3a960bb1158 (
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
|
package org.junit.tests.running.classes;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.junit.runner.notification.RunNotifier;
public class RunWithTest {
private static String log;
public static class ExampleRunner extends Runner {
public ExampleRunner(Class<?> klass) {
log+= "initialize";
}
@Override
public void run(RunNotifier notifier) {
log+= "run";
}
@Override
public int testCount() {
log+= "count";
return 0;
}
@Override
public Description getDescription() {
log+= "plan";
return Description.createSuiteDescription("example");
}
}
@RunWith(ExampleRunner.class)
public static class ExampleTest {
}
@Test public void run() {
log= "";
JUnitCore.runClasses(ExampleTest.class);
assertTrue(log.contains("plan"));
assertTrue(log.contains("initialize"));
assertTrue(log.contains("run"));
}
public static class SubExampleTest extends ExampleTest {
}
@Test public void runWithExtendsToSubclasses() {
log= "";
JUnitCore.runClasses(SubExampleTest.class);
assertTrue(log.contains("run"));
}
public static class BadRunner extends Runner {
@Override
public Description getDescription() {
return null;
}
@Override
public void run(RunNotifier notifier) {
// do nothing
}
}
@RunWith(BadRunner.class)
public static class Empty {
}
@Test
public void characterizeErrorMessageFromBadRunner() {
assertEquals(
"Custom runner class BadRunner should have a public constructor with signature BadRunner(Class testClass)",
JUnitCore.runClasses(Empty.class).getFailures().get(0)
.getMessage());
}
}
|