0% found this document useful (0 votes)
4 views2 pages

Module 14 - Unit Testing With JUnit

The document provides a series of tasks for unit testing using JUnit 5, including writing test cases for basic arithmetic operations, exception handling, setup and teardown processes, object equality, multiple assertions, and disabled tests. Each task outlines specific requirements and methods to be used, such as assertThrows, assertEquals, and assertAll. The document serves as a practical guide for implementing unit tests in Java applications.

Uploaded by

V.K.R Rajput
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Module 14 - Unit Testing With JUnit

The document provides a series of tasks for unit testing using JUnit 5, including writing test cases for basic arithmetic operations, exception handling, setup and teardown processes, object equality, multiple assertions, and disabled tests. Each task outlines specific requirements and methods to be used, such as assertThrows, assertEquals, and assertAll. The document serves as a practical guide for implementing unit tests in Java applications.

Uploaded by

V.K.R Rajput
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like