[Original] Order of JUnit journey

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.