Java Testing
ASecurityUse a JUnit 5 parameterized test. `@ValueSource` is convenient when each case has one input value: ```java import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; class MyCodeTest { @ParameterizedTest @ValueSource(ints = {1, 2, 3, 4, 5}) void calculate_WithInput_ReturnsExpectedResult(int input) { int result = myCode.calculate(input); assertThat(result).isEqualTo(expectedResultFor(input))...
- 584 stars
- 0 votes
- 0 copies
- 3 views
- Added September 5, 2026
Works with
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill java-testing --agent claude-codeAre you the author of Java Testing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-java-testing-eb1688e5)Use a JUnit 5 parameterized test. `@ValueSource` is convenient when each case has one input value:
```java
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
class MyCodeTest {
@ParameterizedTest
@ValueSource(ints = {1, 2, 3, 4, 5})
void calculate_WithInput_ReturnsExpectedResult(int input) {
int result = myCode.calculate(input);
assertThat(result).isEqualTo(expectedResultFor(input));
}
}
```
JUnit runs the same test once for each value, while keeping each invocation isolated. If each case needs multiple inputs or an explicit expected value, use `@CsvSource` instead:
```java
@ParameterizedTest
@CsvSource({
"1, 10",
"2, 20",
"3, 30",
"4, 40",
"5, 50"
})
void calculate_WithInput_ReturnsExpectedResult(int input, int expected) {
assertThat(myCode.calculate(input)).isEqualTo(expected);
}
```
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-10.md
- trigger-11.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
- trigger-6.md
- trigger-7.md
- trigger-8.md
- trigger-9.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.