Skip to content

Use integration testing

B. K. Oxley (binkley) edited this page Jul 25, 2024 · 9 revisions

When we discuss "integration testing", we mean something beyond unit testing. Your team may call it by another name.

In general this means running your application—possibly with fakes, stubs, mocks, spies, dummies, or doubles—for external dependencies (databases, remote REST calls, other services, the file system, etc), and running tests against higher-level functionality in your program (think "frontdoor" calls into your code) but not starting up external dependencies themselves, or calling to existing running services.

Think of CI: "integration tests" are those which do not need your CI to provide other services. Contrast this with System Testing which involves live tests against external systems. Both are valuable: but your development goes faster when local testing can rely on substitions ("mocks") for remote resources.

An example is testing STDOUT and STDERR for a command-line application. (If you are in Spring Framework/Boot-land, use controller tests for your REST services.)

Unlike src/main and src/test, there is no generally agreed convention for where to put integration tests. This project keeps integration tests in src/integrationTest for simplicity of presentation, and they are named "*IT.java". (The choice of test file name is dependent on project.) This pattern is represented in build.gradle and pom.xml. Maven projects may prefer src/it.

If you'd like to keep your integration tests in a separate source root from unit tests, consider these plugins:

Caution: This project duplicates ApplicationIT.java and ApplicationTest.java reflecting the split in philosophy between Gradle and Maven for integration tests. Clearly in a production project, you would have only one of these.

Tips

  • For Maven projects, Apache maintains Failsafe and Surefire plugins as a pair, and share the same version numbers. This project uses a shared maven-testing-plugins.version property
  • Baeldung has a good introduction article on Maven Failsafe

Going further

TODO: Placeholder section

Clone this wiki locally