Skip to content

Instantly share code, notes, and snippets.

@Blizzardo1
Created October 25, 2021 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blizzardo1/569c0c3616419631da7d8d230f3de3f9 to your computer and use it in GitHub Desktop.
Save Blizzardo1/569c0c3616419631da7d8d230f3de3f9 to your computer and use it in GitHub Desktop.
| | Compare | Contrast JUnit | Contrast TestNG | | |
|--------------------|----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|---|
| Initialization | Uses annotations for Initialization and cleanup | Initializes and cleans up at two levels, before and after each method and class. Uses @BeforeEach and @AfterEach for method level and @BeforeAll and @AfterAll for class level. | Initializes and cleans up at two levels, at method and class levels. Uses @BeforeMethod and @AfterMethod at method level and @BeforeClass and @AfterClass for class level. | | |
| Testing Parameters | | Test suite is ran using @RunWith and @Suite annotations. | Uses an XML file to run suite test. | | |
| Ignore Cases | Uses annotations for Ignore cases | Uses @Ignore for ignoring test cases. | Uses @Test annotation with a Boolean parameter enabled for ignoring test cases. | | |
| Exception handling | Has a way to handle exceptions | Uses @Test(expected = ArithmeticException). | Exception test is used to check which exception is thrown. Also uses @Test(expectedExceptiojns = ArithmeticException). | | |
| Timeouts | Has a way to terminate a test if it takes longer than expected | Time test is used to define if the unit test takes longer than expected. If it does, the test will terminate. | Utilizes a timeout to terminate a test which takes a longer time. Uses @Test(timeout = 1000). | | |
| Test Handling | Uses Annotations although differently | @RunWith and @Parameter annotations are used to provide parameter value for the unit test. @Parameter returns List[] and is passed into the class constructor as an argument for parameterized testing. | @DataProvider or XML file is used to provide a parameter for parameterized testing. | | |
| Dependency Testing | | Does not support Dependency Testing, meaning that if one test fails, all test fail. | Supports dependency testing. If initial tests fail, subsequent tests will be skipped. | | |
| Group Testing | | Does not support group testing. | Supports group testing, which dispatches methods into portions and performs groupings of test methods. | | |
| Reports | Provides report on the results of testing | Provides data in XML format but does not create a report for test executions, which is to be generated separately. | By default generates reports for test execution, which includes HTML and XML output. | | |
| Test Order | | Does not support test order. | Supports test order for ordering test methods according to the priority attribute. | | |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment