Test Overview
This test checks if two components work together correctly by verifying their interaction. It ensures that when one component calls another, the expected result is returned.
This test checks if two components work together correctly by verifying their interaction. It ensures that when one component calls another, the expected result is returned.
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; class ServiceA { private final ServiceB serviceB; ServiceA(ServiceB serviceB) { this.serviceB = serviceB; } String process(String input) { String resultFromB = serviceB.transform(input); return "Processed: " + resultFromB; } } class ServiceB { String transform(String input) { return input.toUpperCase(); } } public class IntegrationTest { @Test void testServiceAandBInteraction() { ServiceB serviceB = new ServiceB(); ServiceA serviceA = new ServiceA(serviceB); String input = "hello"; String output = serviceA.process(input); assertEquals("Processed: HELLO", output); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initialized | - | PASS |
| 2 | Creates instance of ServiceB | ServiceB object ready to transform strings | - | PASS |
| 3 | Creates instance of ServiceA with ServiceB injected | ServiceA ready to process input using ServiceB | - | PASS |
| 4 | Calls ServiceA.process with input 'hello' | ServiceA calls ServiceB.transform internally | - | PASS |
| 5 | ServiceB.transform converts 'hello' to 'HELLO' | ServiceB returns 'HELLO' to ServiceA | - | PASS |
| 6 | ServiceA.process returns 'Processed: HELLO' | Output string ready for assertion | Check output equals 'Processed: HELLO' | PASS |
| 7 | Test ends | Test passed successfully | - | PASS |