The basic configuration of JUnit 4 is described here:
<1> Build a Java Project project.
<2> build a package under the SRC directory, COM.SUN.JUNIT4, and write a little file under the package T.java
Package Com.sun.junit4;public class T {//test this method public int add (int x, int y) {return x + y;}}
<3> build a package under the SRC directory, com.sun.test build a Ttest.java below
<4>ttest.java will automatically generate code
Package Com.sun.test;import static Org.junit.assert.*;import Org.junit.test;public class Bbest {@Testpublic void Testadd () {fail ("not yet implemented");}}
The Testadd () method Here is a test method for the T.java Add method, which modifies the code inside to
Package Com.sun.test;import static Org.junit.assert.*;import Org.junit.test;import Com.sun.junit4.t;public class TTest {@Testpublic void Testadd () {int z = new T (). Add (Ten); Assertequals (50,z);//system.out.println ("Test" + Z);}}
<5> Click on Ttest.java to run with the JUnit test method, this window will appear, where the failures is the test fails, you can replace the correct result test can compare the difference
Java-junit's Hello World