JUnit 4
 

-JavaTouch

Summary of the new JUnit 4 style:
- It Requires JDK 5 to run.
- Test classes do not have to extend from junit.framework.TestCase.
- Test methods do not have to be prefixed with ‘test’.
- There is no difference between the old assert methods and the new assert methods.
- It is possible to declare suite-wide initialization method 
- Use @Test annotations to mark a method as a test case.
- @Before and @After annotations take care of set up and tear down.
- @BeforeClass and @AfterClass annotations take care of one time set up and one time tear down.
- @Test annotations can take a parameter for timeout. Test fails if the test takes more time to execute.
- @Test annotations can take a parameter that declares the type of exception to be thrown.
- Support for timeout for test methods 
- JUnit4Adapter enables running the new JUnit4 tests using the old JUnit runners.
- Old JUnit tests can be run in the new JUnit4 runner.

 

 

JUnit is a regression testing framework written by Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java. JUnit is Open Source Software, released under the Common Public License Version 1.0 and hosted on SourceForge.

- JUnit Home (Official)
- JUnit API doc
- JUnit FAQ
- Getting Started with JUnit 4
This article describes basic test writing using JUnit 4.

Tutorials and Articals

- JUnit Reloaded (OnJava , 07 Dec, 2006)
This article describes what's different in JUnit 4 compared to JUnit 3.8.x.
- Get Acquainted with the New Advanced Features of JUnit 4 (DevX, July 24, 2006)
Learn how to migrate from JUnit 3.8 to JUnit 4. Discover version 4's new features, including extensive use of annotations, and find out the status on IDE integration.
- JUnit 4.0 in 10 minutes

IDE Related

Tip: JUnit 4.0 only comes with a textual TestRunner. For graphical feedback, most major IDE's will support JUnit 4 soon. In the meantime, you can run JUnit 4 tests in a JUnit 3 environment by adding the following method to each test class: (Ref: http://junit.sourceforge.net/)

public static Test suite(){
  return new  JUnit4TestAdapter (ThisClass.class);
}


NetBeans IDE
- JUnit 4.0 in NetBeans Home
- Notes about Integrating JUnit4 into NetBeans

 

Build Systems Related

Ant
According the last news from the Ant development community, the Ant development team does not plan to further improve support for JUnit 4.x in Ant. Instead, their idea is that it should be the JUnit development team who would develop and maintain a special Ant task for running JUnit 4 tests. (Ref: http://junit.netbeans.org/junit4/)

 

Forums and Mailing Lists

- JUnit Official Mailing List at Yahoo