Assertions are the core implementation of writing test cases, that is, what the expected value is, and how much is the result of the test to determine whether the test passed.
Assertion Core Method
| Assertarrayequals (expecteds, actuals) |
See if two arrays are equal. |
| Assertequals (expected, actual) |
See if two objects are equal. The Equals () method, similar to the use of string comparisons |
| Assertnotequals (first, second) |
See if two objects are not equal. |
| Assertnull (object) |
View whether the object is empty. |
| Assertnotnull (object) |
View whether the object is not empty. |
| Assertsame (expected, actual) |
See if the references to two objects are equal. Similar to using "= =" to compare two objects |
| Assertnotsame (Unexpected, actual) |
See if the references to two objects are not equal. Similar to using "! =" to compare two objects |
| Asserttrue (condition) |
View whether the run result is true. |
| Assertfalse (condition) |
See if the run result is false. |
| Assertthat (Actual, Matcher) |
See if the actual value meets the specified criteria |
| Fail () |
Let the test fail |
Annotations
| @Before |
Initialize method |
| @After |
Freeing resources |
| @Test |
Test method, where you can test for expected exceptions and time-outs |
| @Ignore |
Ignored test methods |
| @BeforeClass |
For all tests, execute only once and must be static void |
| @AfterClass |
For all tests, execute only once and must be static void |
| @RunWith |
Specifies that a test class uses a runner |
| @Parameters |
To specify a test data collection for a test class |
| @Rule |
Allows flexibility to add or redefine the behavior of each test method in a test class |
| @FixMethodOrder |
Specify the order in which test methods are executed |
A Test class unit test is executed in the following order:
@BeforeClass –> @Before –> @Test –> @After –> @AfterClass
The order in which each test method is called is:
@Before –> @Test –> @After
JUnit Basic Learning-assertion annotations (3)