Eclipse under JUnit quick start

xiaoxiao2021-03-06  26

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.

*** *********************************************************** ********** One or more tests failed! Check the outprut ... *********************************** ************************************ running Ant to complete the test, But there is an annoying problem, that is, Ant actually does not recognize this task, see Ant Home does have ant - junit.jar, even if you put junit.jar in this directory! Depressed, but can solve the following method: Window -> preferences -> Ant -> runtime -> ClassPath, get in junit.jar, very strange, is ClassPath Ant-junit.jar really don't know Why is it, don't put it in junit.jar?

转载请注明原文地址:https://www.9cbs.com/read-40267.html

New Post(0)