Step1:
Right click on Java file a ---> New -> JUnit Test case, you can generate a Test Case, and the default will add TEST before the non-private method in A.
STEP2:
Write this case, below is a simple example:
Public Class Airtest Extends Testcase {Private Air Air; / * * @see Testcase # setup () * / protected void setup () throws exception {air = new air ();
/ * * @See testcase # Teardown () * / protected void teardown () throws exception {}
/ * * Class under test for double h (double, double) * / public void testh () {double result = air.h (0,400); assertequals (400.07, result, 400.07 * 0.01);}
/ * * Class under test for double cp (double, double) * / public void testcp () {double result = air.cp (0,400); assertequals (1.0161, result, 1.0161 * 0.01);}
/ * * Class under test for double CV (Double, Double) * / public void testcv () {double result = air.cv (0,400); assertequals (0.7291, result, 0.7291 * 0.01);}
}
Obviously, I wrote an AIR class, there are three functions, calculated the compression ratio heat, enthalpy, and set to heat, Airtest is to test these three functions, pay attention to Assertequals inside each function, parameter 1 The value, the parameter 2 is the value calculated by the program, and the parameter 3 is the allowable error range.
STEP3
Click Run ... Press New - "Select JUnit -" Click New --- "to run the JUnit's result window, display the results
postscript:
You can integrate the JUnit task to Ant, you can add as follows.