JUNIT / CATATAN</>↗JUnit11 Jul 2026
In JUnit 5, @ValueSource is used with @ParameterizedTest to run the same test multiple times with different simple literal values. Basic example import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.assertTrue; class StringTest { @ParameterizedTest @ValueSource(strings = {"racecar", "radar", "level"}) void palindromeWordsHaveLengthGreaterThanZero(String word) { assertTrue(word.le...
JUNIT / CATATAN</>↗JUnit11 Jul 2026
In JUnit 5, parameterized tests let you run the same test multiple times with different input values. You use: @ParameterizedTest instead of: @Test Then you provide test data using a source annotation such as @ValueSource, @CsvSource, @MethodSource, or @EnumSource. Basic Example with @ValueSource import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.assertTrue; class NumberTest {...
JUNIT / CATATAN</>↗JUnit10 Jul 2026
Short answer Unit test behavior that you own and that can break, especially logic with branches, rules, edge cases, and important failure paths. Do not unit test code that merely repeats the framework, language, or library behavior unless you add meaningful logic around it. Good candidates for unit tests 1. Business rules If the code […]
JUNIT / CATATAN</>↗JUnit10 Jul 2026
Writing JUnit tests is not only about checking whether the code works. Good tests should be clear, reliable, independent, and easy to maintain. Here are common mistakes beginners often make when writing JUnit tests, along with better ways to avoid them. 1. Do Not Let Tests Depend on Each Other Each test should be able […]
JUNIT / CATATAN</>↗JUnit10 Jul 2026
The Arrange-Act-Assert pattern is a simple way to organize unit tests so they are easy to read and understand. A unit test usually answers three questions: Arrange: What data or objects do I need? Act: What behavior am I testing? Assert: What result do I expect? Basic Structure @Test void methodName_expectedBehavior() { // Arrange // […]
JUNIT / CATATAN</>↗JUnit10 Jul 2026
Clean JUnit tests should be easy to understand, focused on one behavior, and safe to change. A good test should tell you: What scenario is being tested What action happens What result is expected Most Java projects today should use JUnit 5, from the org.junit.jupiter package. 1. Use Clear Test Names A test name should […]