Skip to content

Instantly share code, notes, and snippets.

@mfaisalkhatri
Last active December 20, 2024 08:31
Show Gist options
  • Save mfaisalkhatri/2234b442d0f74b9c874a1167fecf4ebd to your computer and use it in GitHub Desktop.
Save mfaisalkhatri/2234b442d0f74b9c874a1167fecf4ebd to your computer and use it in GitHub Desktop.
Feature Description Annotations/Methods
Test Suites Test Suites are basically a group of tests, for example, Smoke, Sanity or a group of tests related to a particular feature.
JUnit allows to create test suites that could be run together.
For using Test Suites, we need to add a JUnit Platform Suite dependency and use the following annotations.
@SelectPackages, @SelectClasses, @Suite
Assertions Assertions are used for verifying the expected behavior of the software. JUnit provides inbuilt assertion methods that can help in easily performing the assertions. There are multiple assertions methods available in the import org.junit.jupiter.api.Assertions; class.
Some of the methods are listed below:
assertTrue(), assertFalse(), assertEquals(), assertAll(), assertNotEquals()
Test Execution Order Customizes the test execution order. It allows the developer to take control of the test execution and run the tests in specific order as required. @TestMethodOrder, @Order, @TestClassOrder
Exception Testing Performs Exception testing that verifies that the required exception is thrown in the test. Following method from the import org.junit.jupiter.api.Assertions; class is used:
assertThrows()
Test Dependencies Test dependencies allow sequential testing by providing the facility to allow test methods to depend on each other. Meaning, the next test method which is dependent on the previous test method will not be executed unless the previous one passes. This is a helpful feature while writing integration tests. @TestInstance
Disable Tests Disables tests or test classes. @Disabled
Timeouts Fails a test if its execution time exceeds a specified duration. @Timeout
Reports Provides a built-in reporter to analyze test results and displays detailed information. Generates a .html file with test execution results. N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment