A few hours ago the final version of JUnit 4.9
appeared on github-e of the popular TDD framework JUnit. What is included in the long-awaited release?
New rules
@Rule
changes were made to the rules introduced in the previous version (
@Rule
). As before, test functionality can be extended with additional Rules at the method level. Now it is possible to define Rules for the performance of entire classes and even test suites. In both cases, the result is achieved by defining a static field with a new annotation
@ClassRule
in acc. test class or in the suite.
And yes, all derivatives from
ParentRunner
including the default
BlockJUnit4ClassRunner
correctly handle the new kind of rules.
An example of a test suite that creates a connection to the server only once and closes it after all the tests of the suite have been completed:
')
<br/>@RunWith(Suite. class )<br/>@SuiteClasses({A. class , B. class , C. class })<br/> public class UsesExternalResource {<br/> public static Server myServer= new Server();<br/> <br/> @ClassRule <br/> public static ExternalResource resource= new ExternalResource() {<br/> @Override <br/> protected void before() throws Throwable {<br/> myServer.connect();<br/> };<br/> <br/> @Override <br/> protected void after() {<br/> myServer.disconnect();<br/> };<br/> };<br/>}<br/> <br/>
The hostess to the note: in the light of these innovations, the former
MethodRule
interface
MethodRule
outdated and received the status of
deprecated
. Rule developers should work with the new
TestRule
interface to enable them to be used with both
@Rule
and
@ClassRule
.
The rules in the JUnit 4.9 suite for the most part have already moved to the new interface. For most users, the change of API is supposed to pass unnoticed and will not require changes in existing tests.
Maven - now officially
Up to now, anonymous volunteers have been building packages for Maven, and the quality of the results left much to be desired. Starting with version 4.9, the JUnit development team takes over this task. I note, however, that judging by the sorts of the official build, JUnit is still happening in Ant. Let's hope that the guys will cope with the new task intelligently and not, for example, the old rake with the transitive dependency of the
junit-dep
package on the
hamcrest-core
(which still has to be cut out exclusion).
What else?
In addition to cosmetic changes in the project structure (the text of the GPL is now part of the samples, the Ant build is now faster) serious bugs were fixed:
- github #
98 : assumeTrue () does not work with expected exceptions
- github #
74 : Categories + Parameterized
- github #
38 : ParentRunner filters more than once
- github #
248 : protected BlockJUnit4ClassRunner # rules method removed from 4.8.2
- github #
187 : Accidental dependency on Java 6
- github #
163 : Bad comparison using assertEquals (String, String)
- github #
227 : ParentRunner now assumes that getChildren () returns a modifiable list
Instead of conclusion
The list of changes generally justifies a minor-release. I express my deep gratitude to the
developers for their gratuitous contribution to improving the quality of the code and congratulate the habrovchan with the good news.