Unit Testing with Junit
1. Basic Test Case
Question:
Write a JUnit 5 test case to verify that the sum of two integers using a [Link](int a, int
b) method returns the correct result.
2. Test Exception Handling
Question:
Write a test case using assertThrows to verify that a method [Link](int a, int b)
throws ArithmeticException when dividing by zero.
3. Setup and Teardown
Question:
Write a test class that uses @BeforeEach and @AfterEach to set up and tear down test data
for each test method. Print messages during setup and teardown to confirm the execution order.
4. Test Object Equality
Question:
Write a test using assertEquals to compare two Person objects with the same state. Override
equals() and hashCode() if needed.
5. Test Multiple Assertions
Question:
Write a single test method that uses assertAll() to validate multiple conditions: a string is not
null, not empty, and contains a specific word.
6. Disabled Test
Question:
Write a test method annotated with @Disabled and add a reason. Demonstrate that the test is
skipped when running the test suite.