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.