????1????Junit???????
????????????????????????????
????A??Junit??÷??????1
????1????Junit????????????
?????????? Java ????—coolJUnit???????coolJUnit ??????? -> ???“Java Build Path”????? -> ???“Add Library…”??? -> ???????“Add Library”?????????? JUnit???????????????汾 Junit 4 ????“Finish”???????????? JUnit ?????????????????
????2??????????????????
?????????????????????????????????е?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? coolJUnit ???????????????? testsrc???????????????????????С?
????3??????????????
?????????SampleCaculator?????????????????????????????????????
public class SampleCalculator {
//?????????????
public int add(int augend?? int addend){
return augend + addend;
}
//?????????????
public int subtration(int minuend?? int subtrahend){
return minuend - subtrahend;
}
}
????4??д??????????
???????SampleCalculator???????????????????????SampleCalculator.java?????????new>?Junit Test Case?????4????Source foler???testsrc???????next?????????????????????add??subtration?????????????finish??ɡ?
????Junit????????????SampleCalculatorTest????????е???????£???
????????assertEquals????????????????????????????????
????assertEquals( [Sting message]?? expected?? actual )
????expected?????????????????????????actual?????????????????????message???????????????????????????????????????????????????
???????????????????????????Java?????????float????double???????????????????????????????
????assertEquals([Sting message]?? expected?? actual?? tolerance)
????????????μ??α???ο??????????????????????????淶??д??
????1. ????????????????? org.junit.Test ???Ρ?
????2. ?????????????? public void ???Σ????????????κβ?????
????5???????н??
????????????????????????????????? Run As JUnit Test?????н?????????????????????????????????????????