First knowledge of JUnit

Source: Internet
Author: User

I. About JUnit

JUnit is a unit test framework for the Java language. Founded by Kent Beck and Erich Gamma, it became the most successful of the Xunit family of Sunit from Kent Beck.

JUnit is a regression testing framework (regression testing framework) written by Erich Gamma and Kent Beck. JUnit testing is a programmer's test, the so-called white-box test, because the programmer knows how the software being tested (how) accomplishes the function and what it does.

Two. get JUnit

download to the latest version of JUnit at Http://www.junit.org .

Three. Examples of JUnit

Four. New and old comparisons of JUnit

-junit3

1. The Unit test class must inherit from the Junit.framework.TestCase class
2. The method name to be tested must begin with test, must be public void and cannot have parameters

-junit4

1. Unit test classes do not have to inherit testcase
2. The test method does not have to be preceded by test, as long as the @test metadata is used to describe

-Metadata (Annotation)--the data used to describe the data.

@Before: Methods that use this metadata are executed one time before each test method executes.
@After: Methods that use this metadata are executed once after each test method executes.

@Test (Expected=*.class): Used to throw an exception.

@Test (TIMEOUT=XXX):
The metadata passed in a time (in milliseconds) to the test method,
If the test method does not run out within the time set, the test also fails.

@ignore:

The test method for the metadata token is ignored in the test.

You can pass a string argument to the label to indicate that the reason is ignored.

First knowledge of JUnit

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.