JUNIT / CATATAN</>↗JUnit13 Jul 2026
If you are learning modern Java testing, the words JUnit Platform, JUnit Jupiter, and JUnit Vintage can be confusing at first. They sound like three different testing frameworks, but they are really three parts of the JUnit 5 ecosystem. The short version is: JUnit Platform runs tests. JUnit Jupiter is the modern JUnit 5 programming […]
JUNIT / CATATAN</>↗JUnit13 Jul 2026
Testing Collections in JUnit In JUnit, you usually test collections with assertions such as: assertEquals assertTrue assertFalse assertIterableEquals assertArrayEquals assertThrows If you are using JUnit 5, import assertions from: import static org.junit.jupiter.api.Assertions.*; 1. Testing a List Use assertEquals when order matters. import org.junit.jupiter.api.Test; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.j...
JUNIT / CATATAN</>↗JUnit13 Jul 2026
In JUnit tests, you usually compare objects with assertions, not with ==. The most common choices are: assertEquals(expected, actual) — compares objects using their equals() method. assertSame(expected, actual) — checks whether both references point to the same object. AssertJ’s assertThat(actual).isEqualTo(expected) — a more fluent alternative. Field-by-field assertions — useful when you only care about some […]
JUNIT / CATATAN</>↗JUnit13 Jul 2026
You can use AssertJ with JUnit to write more readable, fluent assertions than standard JUnit assertions. 1. Add AssertJ Dependency If you use Maven: <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.26.3</version> <scope>test</scope> </dependency> If you use Gradle: testImplementation("org.assertj:assertj-core:3.26.3") 2. Use AssertJ in a JUnit Test Import assertThat statically: import org.junit.jupiter.api.Test; import static org.as...
JUNIT / CATATAN</>↗JUnit13 Jul 2026
You can test repository-like classes without a real database by replacing the database dependency with a fake, mock, or in-memory implementation, depending on what you want to verify. 1. Use mocks for unit tests If your class depends on a repository interface, mock it and verify behavior without touching a database. Example with JUnit 5 […]
JUNIT / CATATAN</>↗JUnit13 Jul 2026
Testing Service Classes with JUnit and Mockito Service classes are usually where your business logic lives. They often depend on repositories, clients, mappers, validators, or other services. When unit testing a service, the goal is usually: test the service logic itself mock external dependencies avoid starting the Spring container unless necessary verify returned values, exceptions, […]