Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 195 lines (151 sloc) 5.403 kb
1708730 Fixed bug 1812200
David Saff authored
1 ## Summary of Changes in version 4.7 ##
2
97afc5e No more Interceptors. Everything is rules
David Saff authored
3 ### Rules ###
28d40d9 Interceptors and Watchmen, because we're just that cool.
David Saff authored
4
97afc5e No more Interceptors. Everything is rules
David Saff authored
5 - Rules allow very flexible addition or redefinition of the behavior
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
6 of each test method in a test class. Testers can reuse or extend one of the
97afc5e No more Interceptors. Everything is rules
David Saff authored
7 provided Rules below, or write their own.
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
8
97afc5e No more Interceptors. Everything is rules
David Saff authored
9 For more on this feature, see http://www.threeriversinstitute.org/blog/?p=155
10
11 - The TemporaryFolder Rule allows creation of files and folders
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
12 that are guaranteed to be deleted when the test method finishes
13 (whether it passes or fails):
14
15 public static class HasTempFolder {
97afc5e No more Interceptors. Everything is rules
David Saff authored
16 @Rule
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
17 public TemporaryFolder folder= new TemporaryFolder();
18
19 @Test
20 public void testUsingTempFolder() throws IOException {
21 File createdFile= folder.newFile("myfile.txt");
22 File createdFolder= folder.newFolder("subfolder");
23 // ...
24 }
25 }
26
97afc5e No more Interceptors. Everything is rules
David Saff authored
27 - ExternalResource is a base class for Rules (like TemporaryFolder)
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
28 that set up an external resource before a test (a file, socket, server,
223b34b Getting started on Interceptors javadoc
David Saff authored
29 database connection, etc.), and guarantee to tear it down afterward:
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
30
31 public static class UsesExternalResource {
223b34b Getting started on Interceptors javadoc
David Saff authored
32 Server myServer = new Server();
33
97afc5e No more Interceptors. Everything is rules
David Saff authored
34 @Rule public ExternalResource resource = new ExternalResource() {
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
35 @Override
36 protected void before() throws Throwable {
223b34b Getting started on Interceptors javadoc
David Saff authored
37 myServer.connect();
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
38 };
39
40 @Override
41 protected void after() {
223b34b Getting started on Interceptors javadoc
David Saff authored
42 myServer.disconnect();
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
43 };
44 };
45
46 @Test public void testFoo() {
223b34b Getting started on Interceptors javadoc
David Saff authored
47 new Client().run(myServer);
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
48 }
49 }
11258fc Added Verifier and ErrorCollector
David Saff authored
50
97afc5e No more Interceptors. Everything is rules
David Saff authored
51 - The ErrorCollector Rule allows execution of a test to continue
11258fc Added Verifier and ErrorCollector
David Saff authored
52 after the first problem is found (for example, to collect _all_ the
53 incorrect rows in a table, and report them all at once):
54
55 public static class UsesErrorCollectorTwice {
97afc5e No more Interceptors. Everything is rules
David Saff authored
56 @Rule
11258fc Added Verifier and ErrorCollector
David Saff authored
57 public ErrorCollector collector= new ErrorCollector();
58
59 @Test public void example() {
60 collector.addError(new Throwable("first thing went wrong"));
61 collector.addError(new Throwable("second thing went wrong"));
62 }
63 }
64
409a8e0 Fixing Interceptor->Rule name changes
David Saff authored
65 - Verifier is a base class for Rules like ErrorCollector, which
11258fc Added Verifier and ErrorCollector
David Saff authored
66 can turn otherwise passing test methods into failing tests if a verification
67 check is failed
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
68
11258fc Added Verifier and ErrorCollector
David Saff authored
69 public static class ErrorLogVerifier() {
70 private ErrorLog errorLog = new ErrorLog();
71
409a8e0 Fixing Interceptor->Rule name changes
David Saff authored
72 @Rule
73 public MethodRule verifier = new Verifier() {
11258fc Added Verifier and ErrorCollector
David Saff authored
74 @Override public void verify() {
75 assertTrue(errorLog.isEmpty());
76 }
77 }
78
79 @Test public void testThatMightWriteErrorLog() {
80 // ...
81 }
82 }
83
97afc5e No more Interceptors. Everything is rules
David Saff authored
84 - TestWatchman is a base class for Rules that take note
20dd074 Added TemporaryFile and ExternalResource interceptors
David Saff authored
85 of the testing action, without modifying it.
86 For example, this class will keep a log of each passing and failing
87 test:
28d40d9 Interceptors and Watchmen, because we're just that cool.
David Saff authored
88
89 public static class WatchmanTest {
90 private static String watchedLog;
91
97afc5e No more Interceptors. Everything is rules
David Saff authored
92 @Rule
93 public MethodRule watchman= new TestWatchman() {
28d40d9 Interceptors and Watchmen, because we're just that cool.
David Saff authored
94 @Override
95 public void failed(Throwable e, FrameworkMethod method) {
96 watchedLog+= method.getName() + " "
97 + e.getClass().getSimpleName() + "\n";
98 }
99
100 @Override
101 public void succeeded(FrameworkMethod method) {
102 watchedLog+= method.getName() + " " + "success!\n";
103 }
104 };
105
106 @Test
107 public void fails() {
108 fail();
109 }
110
111 @Test
112 public void succeeds() {
113 }
114 }
115
97afc5e No more Interceptors. Everything is rules
David Saff authored
116 - The TestName Rule makes the current test name available inside test methods:
507e7b1 Added TestName Interceptor
David Saff authored
117
97afc5e No more Interceptors. Everything is rules
David Saff authored
118 public class NameRuleTest {
119 @Rule public TestName name = new TestName();
507e7b1 Added TestName Interceptor
David Saff authored
120
121 @Test public void testA() {
122 assertEquals("testA", name.getMethodName());
123 }
124
125 @Test public void testB() {
126 assertEquals("testB", name.getMethodName());
127 }
128 }
129
409a8e0 Fixing Interceptor->Rule name changes
David Saff authored
130 - The Timeout Rule applies the same timeout to all test methods in a class:
219beb3 Updated release notes, and added "Oh, yeah, wow" to the test.
David Saff authored
131
132 public static class HasGlobalTimeout {
133 public static String log;
134
409a8e0 Fixing Interceptor->Rule name changes
David Saff authored
135 @Rule public MethodRule globalTimeout = new Timeout(20);
219beb3 Updated release notes, and added "Oh, yeah, wow" to the test.
David Saff authored
136
137 @Test public void testInfiniteLoop1() {
138 log+= "ran1";
139 for(;;) {}
140 }
141
142 @Test public void testInfiniteLoop2() {
143 log+= "ran2";
144 for(;;) {}
145 }
146 }
147
97afc5e No more Interceptors. Everything is rules
David Saff authored
148 - The ExpectedException Rule allows in-test specification
26fa0a4 ExpectedException Interceptor added
David Saff authored
149 of expected exception types and messages:
150
151 public static class HasExpectedException {
97afc5e No more Interceptors. Everything is rules
David Saff authored
152 @Rule
153 public ExpectedException thrown= ExpectedException.none();
26fa0a4 ExpectedException Interceptor added
David Saff authored
154
155 @Test
156 public void throwsNothing() {
157
158 }
159
160 @Test
161 public void throwsNullPointerException() {
162 thrown.expect(NullPointerException.class);
163 throw new NullPointerException();
164 }
165
166 @Test
167 public void throwsNullPointerExceptionWithMessage() {
168 thrown.expect(NullPointerException.class);
169 thrown.expectMessage("happened?");
a402014 ExpectedException allows multiple exceptions
David Saff authored
170 thrown.expectMessage(startsWith("What"));
26fa0a4 ExpectedException Interceptor added
David Saff authored
171 throw new NullPointerException("What happened?");
172 }
173 }
174
aeab84e Include timeout change in release notes
David Saff authored
175 ### Timeouts ###
f67bd3c Updated release notes
David Saff authored
176 - Tests that time out now show the stack trace of the test thread.
aeab84e Include timeout change in release notes
David Saff authored
177
9164fde Hamcrest 1.2 documented in release notes
David Saff authored
178 ### Matchers ###
c618504 Cleaning up compile errors from reverting hamcrest change
David Saff authored
179 - Due to typing incompatibilities, JUnit is still including the 1.1 release
180 of hamcrest. This is not a change from 4.6, but is a change from
a8629da 4.7 final
David Saff authored
181 pre-beta releases of 4.7. Due to this incompatibility, tests using
182 Hamcrest 1.2 must still use the MatcherAssert.assertThat method from
183 Hamcrest, not Assert.assertThat from JUnit.
0b57f03 Minor updates to assertThat and isAnyOf
David Saff authored
184
231238f documentation updates
David Saff authored
185 ### Docs ###
186 - Javadocs now link to online JDK javadocs (bug 2090230)
f9168cb Fix javadoc on Parameterized
David Saff authored
187 - Parameterized runner javadocs improved (bug 2186792)
71ad947 Fixed AfterClass javadoc
David Saff authored
188 - Fixed Javadoc code sample for AfterClass (2126279)
2b9ba55 Fix assertArrayEquals(float[], float[]) javadoc
David Saff authored
189 - Fixed Javadoc for assertArraysEqual(float[], float[])
231238f documentation updates
David Saff authored
190
1708730 Fixed bug 1812200
David Saff authored
191 ### Bug fixes ###
192 - Fixed: BaseTestRunner.getTest() requires class to extend TestCase (1812200)
8b507d7 Incorporated James Abbley's patch for ParallelComputer
David Saff authored
193 - Fixed: Suite does not allow for inheritance in annotations (2783118)
4f9eee5 No change
David Saff authored
194 - Fixed: ParallelComputer skipped tests that took longer than 2 seconds
Something went wrong with that request. Please try again.