0
0
JUnittesting~10 mins

CI pipeline test stage in JUnit - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test runs in a CI pipeline stage to verify that the Calculator's add method works correctly. It checks if adding two numbers returns the expected sum.

Test Code - JUnit 5
JUnit
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

public class CalculatorTest {

    @Test
    public void testAdd() {
        Calculator calc = new Calculator();
        int result = calc.add(2, 3);
        assertEquals(5, result, "2 + 3 should equal 5");
    }
}

class Calculator {
    public int add(int a, int b) {
        return a + b;
    }
}
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test runner starts and loads CalculatorTest classJUnit test environment initialized-PASS
2Runs testAdd() methodCalculator instance created-PASS
3Calls add(2, 3) methodMethod returns integer result-PASS
4Assert that result equals 5Result is 5assertEquals(5, result)PASS
5Test completes successfullyTest marked as passed in report-PASS
Failure Scenario
Failing Condition: add method returns incorrect sum
Execution Trace Quiz - 3 Questions
Test your understanding
What does the testAdd() method verify?
AThat adding 2 and 3 returns 5
BThat the Calculator class exists
CThat the test runner starts correctly
DThat the add method throws an exception
Key Result
Always include clear assertions in your CI pipeline tests to catch errors early and provide meaningful feedback.