This article describes how to use JUnit for the first time. Article (Http://dev.yesky.com/SoftChannel/72342371961929728/20041201/1882557.shtml), I tried to do it again, the results found that it provided above Code The example is incorrect, but the process and images are clear. So you can first look at what it said above. As for the test code, I made a slight change, in order to just explain the problem-it is not difficult.
Code of the tested class:
Public class hellojunit {
Public static int ABS (int n ){
Return n> = 0? N :(-N );
}
}
JUnit test code:
Import JUnit. Framework. testcase;
Public class hellojunittest extends testcase {
Public void testabs (){
Assertequals (hellojunit. Abs (10), 10 );
Assertequals (hellojunit. Abs (-10), 10 );
}
}
Main Code behavior assertequals (hellojunit. Abs (10), 10 );
The parameter indicates:
Hellojunit. Abs (10) ABS method of the execution class hellojunit (the parameter is 10, indicating the absolute value of 10 ).
10 after the comma (,) indicates the expected result (expected value ).
This row compares the expected value (10) with the actual value (the ABS method execution result of the hellojunit class). If not, an exception is thrown.
This is just a simple example. JUnit is known as an excellent white-box automated testing framework. Of course, you will understand it only when you have used it. There is a lot of information on the Internet to introduce this framework. I also learned from my own situation. Of course, learning to use it requires a certain degree of Foundation. The author has the foundation of C and C ++, and the learning of Java has started soon, so here we will share the knowledge we can and hope to improve it together. In addition, I am a full-time tester, so most of the problems described are described from the test perspective. The purpose of learning this framework is to be able to perform white-box testing at work. In the future, we will introduce the white-box testing related theories and tools, and hope you can make better progress together.