JUNIT / CATATAN</>↗JUnit10 Jul 2026
Organizing Tests with Nested Test Classes Nested test classes are a great way to group related tests inside a single test class. In Java, this is commonly done with JUnit 5 using @Nested. They help you structure tests around: A specific method A scenario A state of the object under test Success vs failure cases […]
JUNIT / CATATAN</>↗JUnit10 Jul 2026
In JUnit 5, you can add readable names to your tests using the @DisplayName annotation. @DisplayName lets you show a friendly, human-readable test name in test reports and IDE test runners instead of relying only on the Java method name. Example import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class CalculatorTest { @Test @DisplayName("Adding two positive […]
JUNIT / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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; […]