In this lesson, I introduce integration testing as the middle ground between unit tests and end-to-end tests in the testing pyramid. While unit tests mock dependencies and end-to-end tests treat the application as a black box, integration tests verify the interaction between components using real services. We implement an integration test for the `StagedDiff` function, which retrieves staged changes from a Git repository—but instead of mocking Git, we test against a real Git repo.
The implementation involves creating a temporary directory, initializing a Git repository, adding test files (hello.txt and bye.txt), staging only one file, and then verifying that our `StagedDiff` function correctly returns only the staged changes. We encounter an interesting challenge where the test runs in the wrong directory, which we solve by changing the process's working directory during the test and carefully restoring it afterward. This practical example demonstrates how integration tests provide confidence that our code works with real external systems while still maintaining reasonable test isolation and cleanup.