The use of JUNIT4 in Java

Source: Internet
Author: User

Junti Test Project:

Software Development process: Project research, demand analysis, software design, program coding, software testing, operation and maintenance.

Common methods of testing:

Black box test: No need to consider the internal structure of testing software

White Box testing: The internal structure of the test code needs to be clear

Regression test: Refers to the program code is modified, re-test, verify that the changes did not raise a new error.

Unit Test: A function or block of code in the main test program.

JUnit Framework Composition: TestCase, TestSuite, Testrunner three classes

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/49/4A/wKioL1QSeWiz_lEdAAHZa7_xxh4887.jpg "title=" Several common classes of JUnit "alt=" wkiol1qsewiz_ledaahza7_xxh4887.jpg "/> Test results testresult:

Error: Indicates an error in the code itself.

Failures: The assertion is inconsistent with the expected result and the test fails.

junit--Reflection Technology

JUNIT4--JDK annotation Technology

Junit4 commonly used annotations:

     @Before: Used to annotate the method to be executed before each test method executes

     @After: A method for labeling the execution of each test method

     @Test: Used to label a test method
    
     @Ignore: A test method for labeling pending participation
    
      @BeforeClass: The method of labeling runs the

     @AfterClass one time before all test methods of the entire class are run: The method of labeling is run at the end of all test methods of the entire class at run-time

to test the code with JUNIT4:

1. Create a tested class

2. Import JUNIT4 Rack Package

3. Create a test class (the test code and the test code are in a different directory than the package)

4. Select test Method

5. Create an instance of the class being tested, call the test method of the test class object in the test method, and use the
Assert.assert method.

For example:

Calculator cal =new Calculator ();    @Test public void Add () {Cal.add (3);    Cal.add (2);     Assertequals (5,result); }

Tips for using:

1. The unit test code and the test code are different directories.

Note @test in the test class in 2.JUNIT4 must have, the method name does not need to start with test, and the test method must be
Public modifier, the return value must be void and cannot have parameters. This test party is ignored @Ignore added.

3.JUNIT4: Import static org.junit.assert.*, static import will not need to use the

Assert.assert* () method, direct assert* () method.




This article is from "Rock" blog, please make sure to keep this source http://chi474879271.blog.51cto.com/9253467/1551540

The use of JUNIT4 in Java

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.