????1.2Junit??????????

????JUnit---SourceForge???---IBMCommon Public License ---????:www.junit.org

????ASP??C++??c#??Effel??Delphi??Perl??PHP??Python??REBOL??Smalltalk??Visual Basic??

????xUnit?????:1.???????д???????????????????????????????2.?????????????????????????????????е????????μ?????

????Junit????:

??????????????????????????

?????????????????????????????????????????????????????

?????????????????????????У?JUnit??Ant??????????????

????Junit??????????????????ж??ο???

?????????????JUnit???????

????Junit?????д?????:

????????????д?????????????????????????????????д

???????????????????

???????????ü??е????????д???????

????Junit??????:

????????????????ж?????????????????????Boolean?

?????????????豸??ù?????????????????

???????????????????????????

?????????ν????????????????

????JUnit????7??????????????junit.framework??junit.runner??Framework??????????????????????Runner???????????????

????JUnit??4?????????:TestSuite??TestCase??TestResult??TestRunner???????????Framework?????????????????????????????????????????????????????????????????ν???

????TestResult:???????TestCase????е????????????????Failure?????????Error???????????????????TestListener(?y????TestRunner????)???д???

????TestRunner:?????????????????????????????????и???????????????????????????????????

????TestSuite:???????????????е?TestCase

????TestCase:??????????????е???????????????????г???????????????????.

???????????????:Test??TestListener

????Test:????????????:run()??countTestCases()-->????????????????????

????TestListener:addError()??addFailure()??startTest()??endTest()-->????????????????????????????????????????????????

????Junit??????:TestCase(??junit.swingui.TestRunner??????)??TestSuite(?????)??TestResult(??????????????)??TestListener(?????????)??TestFailure(???????)??AssertionFailedError.

????Junit??Eclipse????????????ο???JUnit in Action??

????Junit???????д???:java junit.textui.TestRunner  xxx

????1.3JUnit???

????1.3.1. ????????:

????Eclipse??JUnit??Ant

????1.3.2. ??????????????????ж????:

class Triangle{
private double a?? b?? c;
public Triangle ( double a?? double b?? double c ){
this.a = a;
this.b = b;
this.c = c;
}
/*
?????? 1 ?????????????
?????? 2 ??????????????
?????? 3 ???????????????????
??????-1 ????????????????
*/
public int type (){
//to be added
}
}

????1.3.3?????? JUnit ???????????????????????????

????(1)????????????????ε????????

????(2)???????????????ε????????

????(3)????????????????ε????????(???:???????????????)

????(4)?????????????????????ε????????

????(5)????????????????????

????4????д ant ???????????????

??????????????????к???????????

???????:????????JVM??Open JDK6.0??eclipse??3.8 Juno??JUnit??????4.11