Java program unit test-analyze and obtain test cases

Source: Internet
Author: User
Author: keld H. Hansen Translation: cmanlh original address

I. Introduction
2. Enter JUnit's paradise
Iii. Round class
4. Analyze and obtain test cases

Analyze and obtain test cases
With the development of Web projects, more and more test cases are established and executed independently. However, as the number increases, one-on-one execution is very tedious and boring. Can I run multiple or all of the test cases at a time? It will feel great. In fact, by using testsuite, this idea is very easy to implement. Use testsuite to organize other test cases in one test case to form a super test case:

Package Hansen. playground;

Import JUnit. Framework .*;

Public class testall extends testcase ...{
Public testall (string name )...{
Super (name );
}

Public static void main (string [] ARGs )...{
JUnit. textui. testrunner. Run (Suite ());
}

Public Static Test Suite ()...{
Testsuite suite = new testsuite ();
Suite. addtest (testcourse. Suite ());
Suite. addtest (testround. Suite ());
Return suite;
}
}

In the sample code, "testall" can be included by other test cases, and these "other test cases" can be included by other test cases ...... In fact, this practice forms the organizational level of a test case.

With this hierarchical relationship, you can execute test cases of any level at any time as required by the system.

Conclusion
With the unit test framework JUnit or similar frameworks, the project has been significantly improved in coding production and quality from the very beginning. In addition, there are many other advantages. Test cases can also be used as development documents for tested programs. When a bug occurs in the system, you only need to write a test case for the bug and output the test results to prove that the test case can discover the bug. After the bug is fixed, run the test case again to check whether the repaired program can pass the test. If it passes the test, it indicates that the bug has been fixed. Because testsuite can be used to test any updated part of the system, it can effectively prevent fixing bugs from being messed up again in the system.

Remember, when using a tool or technology, the first thing is to read its instruction documents and then use them. If you are a Java programmer, I strongly recommend that you try JUnit or similar tools. I'm sure you will never regret it.

Some JUnit Resources
Www.junit.org-official JUnit website

Junit.sourceforge.net-documentation and some useful articles

Http://www.clarkware.com/articles/junitprimer.html-a concise introduction to junit

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.