Unit and Integration Testing
Unit tests check a small piece of code in isolation. Integration tests check that real parts of a system, such as an application and its database, work together across a boundary.
itSoftware engineering | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic — Unit and Integration Testing
Automated testing is a way to turn a claim about software into something the build can check repeatedly. It is not a certificate of universal correctness, sadly. It is evidence about the behavior somebody had the good sense to name before a change made it mysterious.
The first useful split is unit test versus integration test. A unit test keeps its attention on one unit of work under the team's control. A canceled order must not become paid, for example. Give it the required state, ask for payment, and check for the defined error. The database, network, clock, and other travelling circus stay outside the tent.
An integration test points at a seam: the place where independently sensible parts must agree. An application and a database must agree about a schema. An HTTP adapter and another service must agree about a message. A test can be perfectly correct about a pricing rule while having absolutely no idea whether its SQL works. Both facts can be true. Software is very accommodating that way.
Test doubles help keep this boundary honest. A stub returns prepared data. A fake is a small working replacement. A mock checks an interaction when sending that interaction is itself the requirement. They are not miniature copies of every dependency. Once a test starts reenacting private helper steps, it has begun testing the furniture arrangement rather than the house.
The surprising part is that a bigger test is not automatically better evidence. Broad user journeys matter for critical wiring, but they usually cost more to run and explain. A portfolio keeps many focused unit checks close to the rules, selected integration checks near important seams, and only a few broad journeys. The risk and the feedback cost choose the mix; a geometric shape does not get a vote.
Passing tests only speak for the behavior they exercised. A flaky test, one that changes result without a material product change, speaks in static. Control time, random values, identifiers, and test data. Wait for a defined completion condition instead of a fixed sleep. Then a failure can say what happened rather than merely announcing that something somewhere has developed feelings.
Read the Intro for the full boundary map and the glossary. Use Slides when the portfolio and seam relationships need a quick visual pass. Keep the Cheatsheet beside the test code for doubles, assertions, and diagnostic signals. Then use the Practice Reference to turn one behavior and one seam into evidence you can trust.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://learn.microsoft.com/en-us/dotnet/core/testing/
Supports
- Unit tests exercise individual components or units of work under developer control without infrastructure concerns
- Integration tests exercise two or more components working together and often include infrastructure concerns
- Test platforms execute tests while frameworks supply author-facing attributes and APIs
- https://docs.junit.org/current/user-guide/
Supports
- JUnit Jupiter provides a programming model for writing tests and an extension model
- JUnit documentation covers assertions, parameterized tests, lifecycle, execution, and build-tool support
- https://martinfowler.com/articles/practical-test-pyramid.html
Supports
- The test pyramid groups tests by granularity and guides a balanced test portfolio
- Unit tests, integration tests, contract tests, end-to-end tests, and deployment pipelines address different feedback needs
- Test doubles and interaction testing need deliberate use
- Database and service boundaries are focused integration-test targets
- https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests
Supports
- Official ASP.NET Core integration-testing guidance for web applications
- https://github.com/TheJambo/awesome-testing
Supports
- Curated discovery of testing tools including Testcontainers, Pact, and Playwright
- https://en.wikipedia.org/wiki/SUnit
Supports
- Kent Beck created SUnit in 1989 as an automated testing framework for Smalltalk
- https://en.wikipedia.org/wiki/Unit_testing
Supports
- Kent Beck and Erich Gamma developed and released JUnit in 1997
- https://martinfowler.com/bliki/TestPyramid.html
Supports
- Mike Cohn developed the test automation pyramid in conversations during 2003 and 2004 and described it in a 2009 book
- Broad GUI tests are slower and more brittle than focused tests in the usual case
- https://testing.googleblog.com/2010/06/test-driven-integration.html
Supports
- An integration test can exercise two components together in small increments
- https://testing.googleblog.com/2010/12/test-sizes.html
Supports
- Google defines Small, Medium, and Large tests through constraints on infrastructure and timing
- Tests must run in any order to support reliable parallel execution
- https://testing.googleblog.com/2015/04/just-say-no-to-more-end-to-end-tests.html
Supports
- A focused integration test can replace an end-to-end test when it detects the same defect
- https://docs.junit.org/5.0.1/user-guide/index.pdf
Supports
- JUnit 5 M1 was released on 2016-07-07 and introduced the JUnit Platform and Jupiter direction
- https://testing.googleblog.com/2021/06/how-much-testing-is-enough.html
Supports
- Unit tests, integration tests, and end-to-end checks have complementary roles in a test strategy
- https://www.moderntreasury.com/journal/improving-build-reliability-by-reducing-integration-tests
Supports
- Rerunning unreliable integration tests in isolation did not reproduce suite-level flaky behavior in Modern Treasury's investigation
- https://junit.org/
Supports
- JUnit is an open-source test framework for Java
- https://pytest.org/
Supports
- pytest is an open-source test framework for Python
- https://jestjs.io/
Supports
- Jest is an open-source testing framework for JavaScript and TypeScript
- https://xunit.net/
Supports
- xUnit.net is an open-source test framework for .NET
- https://testcontainers.com/
Supports
- Testcontainers provides disposable dependency environments for integration tests
