JUnit Study Notes

Source: Internet
Author: User

Org. JUnit. Assert .*;

1. Setup and teardown: these two methods are provided in JUnit framework for initialization and anti-initialization of each test method.
Setup is called before each test method call and is responsible for initializing the test environment required for the test method;
Teardown is called after each test method is called and is responsible for revoking the test environment.
The basic test procedure is as follows:
Test start-> setup-> testxxx-> teardown-> test end

2. Public static void fail (Java. Lang. String message) Output Error Message

3. Test the assembly of testsuite. You can add all testcase calls to testsuite. Similarly, you can add another testsuite to testsuite.

4. static import: Add static after the import keyword, and then call the methods in this class is no different from calling your own methods, such as assertequal (sorted Ted, actual ), this function can be directly called
You do not need to add the class name or instance object.

5. @ test (Arg...) is automatically executed by the annotation monk method in juint. This annotation can only modify the public void method.

6. @ test parameter Timeout: specifies the time when the method is executed. If a parameter is set, the modified method must be executed at the end of the event; otherwise, an exception is thrown. Syntax: @ test (timeout = 1) // The unit of time is millisecond.

7. @ test parameter expected: specifies that this method is used to exclude exceptions. If this parameter is set, the blame modifier can pass the test only when the exception specified by this parameter is excluded. Otherwise, the test fails. For example
@ Test (expected = arithmeticexception. Class)
Public void testexceptedf (){
Int I = 1/0;
}
In this case, testexceptionf throws an arithmeticexception, so the test passes. If the test fails, the error track is listed in the failure trace panel.

8. @ After: The method modified by this annotation will be executed once after each test method is executed. This annotation can only modify the public void method.

9. @ before: the method modified by this annotation will be executed once before each test method is executed. This annotation can only modify the public void method.

10. @ afterclass: The annotation method will be executed once after all test methods are executed. This annotation can only modify the public static void method.

11. @ beforeclass: The method modified by this annotation will be executed once before all test methods are executed. This annotation can only modify the public static void method.

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.