JUNIT / NOTES</>↗JUnit10 Jul 2026
In JUnit 5, you can disable a test by annotating it with @Disabled from the org.junit.jupiter.api package. Disable a Single Test Method import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; class CalculatorTest { @Test @Disabled void divisionByZeroTest() { // This test will be skipped } } When you run the test suite, this test will not be executed. Add […]
JUNIT / NOTES</>↗JUnit09 Jul 2026
The JUnit test lifecycle describes the order in which JUnit creates test objects, runs setup code, executes test methods, and performs cleanup. Understanding this lifecycle helps you write tests that are clean, predictable, and easy to maintain. This guide focuses on JUnit 5, also known as JUnit Jupiter. 1. What Is the JUnit Test Lifecycle? […]
JUNIT / NOTES</>↗JUnit09 Jul 2026
In JUnit 5, @BeforeAll and @AfterAll are lifecycle annotations used to run setup and cleanup code once per test class. They are useful when you need to initialize or clean up expensive shared resources, such as: database connections test containers temporary directories mock servers shared test data application-wide configuration Basic Rule By default, methods annotated […]
JUNIT / NOTES</>↗JUnit09 Jul 2026
In JUnit 5, @BeforeEach and @AfterEach are lifecycle annotations. They let you run code before and after every test method. Annotation When it runs Common use @BeforeEach Before each @Test method Create objects, initialize test data, reset state @AfterEach After each @Test method Clean up resources, close files/connections, reset temporary state Basic Example import org.junit.jupiter.api.AfterEach; […]
JUNIT / NOTES</>↗JUnit08 Jul 2026
JUnit itself does not require one specific naming convention for test methods, especially in JUnit 5. A test method is recognized because it is annotated with @Test, not because of its name. That said, good test names are crucial because they explain what behavior is being tested. 1. Test Class Naming A common convention is […]
JUNIT / NOTES</>↗JUnit08 Jul 2026
Testing Exceptions with assertThrows() in JUnit 5 Use assertThrows() when you expect a piece of code to throw a specific exception. Basic Syntax ExceptionType exception = assertThrows( ExceptionType.class, () -> { // code that should throw the exception } ); For JUnit 5, import it like this: import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertThrows; Simple Example import […]