Member-only story
Prefer Integration Tests Over Unit Tests
The pros of not writing unit tests
I have a controversial stance on testing practices. I’ve been in various teams and companies, and my approach to testing usually raises eyebrows.
In short, I tend not to write unit tests. I instead write many integration tests and rarely use mocks. In my experience, such an approach allows me to deliver changes faster and more confidently. The application becomes easier to maintain too. I’m going to unpack my rationale on why that is the case. Please note that I mainly work on the backend, so use this lens when reading.
Unit and Integration Test Definition
Most of the jargon in software engineering has loaded meanings. Unit and integration tests are some of them. Let’s first understand my definition so we are on the same page. Let’s also use an example to put things concretely.
Say we have an application that manages customers’ carts. The customer adds and removes items from their cart by using this application. Internally, this module is comprised of multiple classes, such as the CartPricing
and CartValidator
class. The module also uses Postgres to store the actual item. The architecture diagram of the application is represented in Figure 1.

A unit test is against a small component (usually a class) in the application. If the component requires other components, the other components are usually mocked. In the example above, unit tests are tests that exercise each class in isolation, such as CartPricingTest
, CartValidatorTest
, CartServiceTest
, and CartControllerTest
as depicted in Figure 2. The test will look like this:
void addItemSuccess() {
when(cartItemsRepository.addItem(eq(1))).thenReturn(true);
cartService.addItemById(1);
verify(cartItemsRepository).addItem(1);
}
An integration test is a test against the application’s behavior. This test usually includes multiple classes and uses actual external dependencies like databases. In the example above, integration tests will use the application’s external-facing…