JUNIT / CATATAN</>↗JUnit07 Jul 2026
In JUnit, assertions are used to verify that your code produces the expected result. If an assertion fails, the test fails. JUnit 5 assertions are provided by the org.junit.jupiter.api.Assertions class. Basic Example import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class CalculatorTest { @Test void testAddition() { int result = 2 + 3; assertEquals(5, result); } } In […]
JUNIT / CATATAN</>↗JUnit07 Jul 2026
Using @Test in JUnit In JUnit, @Test is an annotation that marks a method as a test method. When you run your tests, JUnit looks for methods annotated with @Test and executes them automatically. 1. Add the Correct Import For JUnit 5, use: import org.junit.jupiter.api.Test; You will usually also import assertions such as: import static […]
JUNIT / CATATAN</>↗JUnit07 Jul 2026
A basic JUnit test class is just a Java class that contains one or more test methods. Each test method checks whether a small piece of code behaves the way you expect. Here is a simple JUnit 5 example: import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class CalculatorTest { @Test void shouldAddTwoNumbers() { int result = 2 […]
GRADLE / CATATAN</>↗Gradle07 Jul 2026
To add JUnit to a Gradle project, add the JUnit dependency to your build.gradle or build.gradle.kts file and configure Gradle to use the JUnit Platform. If you use Groovy Gradle: build.gradle For JUnit 5, add: plugins { id 'java' } repositories { mavenCentral() } dependencies { testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2' } test { useJUnitPlatform() } If you […]
JUNIT / CATATAN</>↗JUnit07 Jul 2026
To add JUnit to a Maven project, you add the JUnit dependency to your project’s pom.xml, create test classes under src/test/java, and run the tests with Maven. 1. Add JUnit to pom.xml For modern Java projects, use JUnit 5. <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.13.4</version> <scope>test</scope> </dependency> </dependencies> If your pom.xml already has a <dependencies> section, […]
JUNIT / CATATAN</>↗JUnit07 Jul 2026
Unit testing in Java means testing small pieces of code — usually one method or one class — in isolation. The most common testing framework for modern Java projects is JUnit 5, also known as JUnit Jupiter. This guide shows the basic steps to start writing unit tests with JUnit. 1. Add JUnit to Your […]