0
0
JUnittesting~10 mins

Custom display names for parameters in JUnit - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses JUnit to run a parameterized test with custom display names for each parameter set. It verifies that the sum of two numbers matches the expected result.

Test Code
JUnit
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

public class CalculatorTest {

    @ParameterizedTest(name = "Sum of {0} and {1} should be {2}")
    @CsvSource({
        "1, 2, 3",
        "4, 5, 9",
        "10, 20, 30"
    })
    void testSumWithCustomDisplayName(int a, int b, int expected) {
        assertEquals(expected, a + b);
    }
}
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test runner starts and loads CalculatorTest classJUnit test environment initialized-PASS
2JUnit identifies parameterized test method testSumWithCustomDisplayName with 3 parameter setsTest method ready to run with parameters (1,2,3), (4,5,9), (10,20,30)-PASS
3JUnit runs testSumWithCustomDisplayName with parameters (1, 2, 3)Test method executing with a=1, b=2, expected=3assertEquals(3, 1 + 2)PASS
4JUnit runs testSumWithCustomDisplayName with parameters (4, 5, 9)Test method executing with a=4, b=5, expected=9assertEquals(9, 4 + 5)PASS
5JUnit runs testSumWithCustomDisplayName with parameters (10, 20, 30)Test method executing with a=10, b=20, expected=30assertEquals(30, 10 + 20)PASS
6Test runner completes all parameterized tests and reports resultsAll parameterized tests passed with custom display names shown in test report-PASS
Failure Scenario
Failing Condition: One of the parameterized test cases has an incorrect expected sum
Execution Trace Quiz - 3 Questions
Test your understanding
What does the custom display name in the parameterized test show?
AThe class name only
BThe sum calculation details for each parameter set
CThe default method name without parameters
DThe test execution time
Key Result
Using custom display names for parameters helps make test reports clearer and easier to understand by showing exactly what each test case is checking.