---
title: "Integration Tests vs. Unit Tests: Why Integration Tests Matter More | CoderPad"
description: "Unit tests are good, but integration tests may be better for testing what really matters."
canonical: "https://coderpad.io/blog/development/integration-tests-vs-unit-tests-integration-matters-more/"
last_modified: "2023-06-05 14:28:33"
---
[Back to blog](https://coderpad.io/blog/)

# Integration Tests vs. Unit Tests: Why Integration Tests Matter More

March 29, 2022 5 Minute Read

By Ken Swearengen

[Development](https://coderpad.io/blog/development/)![Header image](https://coderpad.io/wp-content/uploads/2022/03/Unit-Test-vs-Integration-Tests-Header-Image.png)

In the hierarchy of things developers like to do, writing tests falls at about the “necessary evil” level. Like eating a heaping pile of spinach, we know it’s good for us–but getting motivated to do it can be a struggle. Of course running the proper tests saves us a whole lot of time and money fixing bugs down the line, but even then there are usually a million other things we’d rather do than write tests.

Luckily for us, many other software developers also didn’t like doing it, so they created lots of automated testing tools to make it easier. These days you can find a tool for just about any testing type and programming language.

For end-to-end testing you have your choice of tools like [Cypress](http://cypress.io/), [Pupp](https://github.com/puppeteer/puppeteer) [e](https://github.com/puppeteer/puppeteer) [teer](https://github.com/puppeteer/puppeteer), [Webdriver](https://webdriver.io/), and [Selenium](https://www.selenium.dev/).

Unit, integration, and static testing tools tend to be more language-specific. Popular tools like [JUnit](https://junit.org/junit5/), [Jest](https://jestjs.io/), [pylint](https://pylint.org/), [mocha](https://mochajs.org/), and [Visual Studio’s built-in unit test feature](https://docs.microsoft.com/en-us/visualstudio/test/?view=vs-2022) make it easier to automate your testing set-up.

But no matter which tools you decide to use, it’s essential to know how — and when — to use them.

## Learn how to run front-end developer interviews that don’t suck

[Read our guide](https://coderpad.io/blog/interviewing/5-tips-for-interviewing-frontend/)

## Different tests for different purposes

Usually, the choice between what test to use boils down to the tradeoffs between the time/costs of running that test and your confidence in the test results. We’ve graded four testing types—end-to-end, integration, unit, and static—on a scale of 1-4 💲(cost/time) and![👍](https://coderpad.io/assets/emoji/1f44d.svg) (confidence) to help you understand when to deploy each.

### End-to-end testing

Cost/Time | | | Confidence
💲💲💲💲 | |
| |
![👍](https://coderpad.io/assets/emoji/1f44d.svg)![👍](https://coderpad.io/assets/emoji/1f44d.svg)![👍](https://coderpad.io/assets/emoji/1f44d.svg)![👍](https://coderpad.io/assets/emoji/1f44d.svg)

End-to-end testing tests the application from start to finish. It tests the entire user journey of an application, mimicking the quality issues a user might encounter while trying to carry out an action in your application. Generally, these tests are the most time & money intensive but will also [give you the most confidence](https://kentcdodds.com/blog/write-tests) that your application won’t bug out on users.

End-to-end tests are expensive because they require more heavily powered servers to spin up and take longer to complete (time = money).
They take so much longer because instead of mocking out the backend, they make calls against a real server. While this is good because it can catch a lot, it’s bad because if an end-to-end test fails, it may not be because of the frontend’s code but maybe because the backend is having problems.

### Integration testing

Cost/Time | | | Confidence
💲💲💲 | |
| |
![👍](https://coderpad.io/assets/emoji/1f44d.svg)![👍](https://coderpad.io/assets/emoji/1f44d.svg)![👍](https://coderpad.io/assets/emoji/1f44d.svg)

Integration testing tests interactions between components – think between backend services or components in a frontend framework.

These tests are necessary to make sure components work correctly together – your unit tests may show that each part works correctly, but there may be data or logic errors that only show up when the components are tested outside of isolation.

Integration tests are cheaper since you can spin up a much lighter process to run the test but still catch many potential issues. We’ll discuss more why you should focus on integration testing below.

### Unit testing

Cost/Time | | | Confidence
💲💲 | |
| |
![👍](https://coderpad.io/assets/emoji/1f44d.svg)![👍](https://coderpad.io/assets/emoji/1f44d.svg)

Unit tests don’t test integration with any other part of the code but instead centralize on a specific bit of code and make sure a particular set of inputs match a set of outputs – [like conditional logic and function calls.](https://smartbear.com/learn/automated-testing/what-is-unit-testing/)

Because of this focus on smaller bits of logic and data processes, they’re great for testing libraries.

### Static testing

Cost/Time | | | Confidence
💲 | |
| |
![👍](https://coderpad.io/assets/emoji/1f44d.svg)

Static testing is your basic linting or static code analysis. It helps you find fundamental issues like typos and missing characters. Static tests are the quickest and cheapest test to run but won’t give you much confidence in the quality of the entire application.

Static tests are commonplace and utilized in almost every IDE and every language.

## The understated importance of integration testing

Prominent software engineers like Kent C. Dodds of Remix.run and Guillermo Rauch of Vercel advocate for a bigger emphasis on integration tests since they cost less than end-to-end testing but cover more than unit tests.

To help explain his viewpoint, Dodds created the “testing trophy” – an updated version of [Martin Fowler’s “testing pyramid.”](https://martinfowler.com/bliki/TestPyramid.html)

![testing pyramid with e2e at top integration tests at middle and unit tests at bottom](https://coderpad.io/wp-content/uploads/2022/03/img_623c8e4bbc328.png) | ![testing trophy with static tests at bottom then unit tests then large section of integration tests and then e2e small at the top](https://coderpad.io/wp-content/uploads/2022/03/img_623c8e4d68668.png)
Testing Pyramid | Testing Trophy

Fowler’s pyramid is pretty well known – it shows that as costs rise, the speed of a test tends to decline, hence why many developers minimize E2E testing and maximize unit testing. The testing trophy, on the other hand, is a bit less obvious, so here’s how Dodds describes it:

>

The general idea is that you get *great* value for the cost out of static analysis tools and integration tests. Then you get *good* value out of unit and e2e tests. Use them all.

[Kent C. Dodds](https://twitter.com/kentcdodds/status/960723176031272962)

Part of the great value of integration tests is that they still test user behavior like end-to-end tests. Users will rarely be using components in isolation, rather most software runs as a series of interactions among different components — and it’s exactly these interactions that integration testing is verifying. This makes them a confidence improvement on unit tests, which simply test inputs and outputs of a particular piece of logic. Or, to put it another way:

>

It doesn’t matter if your component <A /> renders component <B /> with props c and d if component <B /> actually breaks if prop e is not supplied. So while having some unit tests to verify these pieces work in isolation isn’t a bad thing, it doesn’t do you any good if you don’t also verify that they work together properly. And you’ll find that by testing that they work together properly, you often don’t need to bother testing them in isolation.

[Kent C. Dodds](https://kentcdodds.com/blog/write-tests)

Of course, this is only true of well-written integration tests.

## What makes a good integration test?

You should try to mock out as little as possible with good integration tests. You want to maximize the amount of application functionality that you test.

This is not a natural testing inclination, especially if most of your testing experience has been in unit testing. A notable example of this in frontend development is the predisposition to creating [“Shallow Render” tests](https://enzymejs.github.io/enzyme/docs/api/shallow.html).

Shallow Render tests only test a single component rather than the interaction of multiple elements on a screen. But this tends to be bad practice since it won’t catch issues with the integration between multiple components.

If you’re one of the developers with a bias towards mocking and shallow rendering, you’ll have to pay extra attention to make sure that your integration tests actually test interactions between your different components.

There’s a trend towards emphasizing integration tests as part of an overall testing framework, and there’s a good reason it’s not going away anytime soon:

>

Integration tests strike a great balance on the trade-offs between confidence and speed/expense. This is why it’s advisable to spend most (not all, mind you) of your effort there.

[Kent C. Dodds](https://kentcdodds.com/blog/write-tests)

A comprehensive testing strategy will use a combination of the four different testing types; however, it’s hard to beat the bang-for-the-buck that integration tests provide.

## Subscribe for more CoderPad insights

## Trending Articles

Previous slide Next slide [Development

## What is Prompt Engineering?

Introducing AI tools such as ChatGPT and Bard helps increase the efficiency of tasks such as data generation, code generation and completion, text summarization, etc. How were these AI tools trained to answer almost every question you ask them? The answer, prompt engineering, is discussed in this blog post.

Read the post](https://coderpad.io/blog/development/what-is-prompt-engineering/) [Development

## A Guide To Using React’s useCallback() Hook

Are you looking to optimize your React applications? Have you heard of the useCallback hook? useCallback is a powerful React hook that helps you optimize your application by preventing unnecessary re-renders. In this post, we'll dive into React's useCallback() hook, define referential equality and callback functions and how to tie it all together.

Read the post](https://coderpad.io/blog/development/a-guide-to-using-reacts-usecallback-hook/) [Development

## MySQL vs. PostgreSQL: How Do They Compare?

A database is a convenient tool that allows users to access information, maintain records, and apply commonly used operations, such as insertion, modification, deletion, and data organization. Learn about MySQL vs PostgreSQL, their features, advantages, and disadvantages. Finally, check out which one is the best choice for you.

Read the post](https://coderpad.io/blog/development/mysql-vs-postgresql-how-do-they-compare/) [Development

## PostgreSQL LIKE Operator: A Detailed Guide

When using databases, searching for values that match a given pattern is a familiar necessity. Learn how you can retrieve entries with queries including a particular string using Postgres LIKE operator.

Read the post](https://coderpad.io/blog/development/postgresql-like-operator-a-detailed-guide/) [Development

## How To Use DataProvider In TestNG With Examples

When it comes to testing there are many tools and techniques available. In this post, we'll discuss how to use DataProvider with TestNG.

Read the post](https://coderpad.io/blog/development/how-to-use-dataprovider-in-testng-with-examples/) [Development

## How To Get Up And Running With Django Migrations: A Guide

Django migrations are a way of handling the application of changes to a database schema. By following the steps outlined in this guide, you can easily set up and use migrations in your Django projects.

Read the post](https://coderpad.io/blog/development/how-to-get-up-and-running-with-django-migrations-a-guide/) [Development

## Writing A Parameterized Test In JUnit With Examples

A JUnit parameterized test allows you to decouple data from structure, generating cleaner and more reliable tests. Learn more in this guide.

Read the post](https://coderpad.io/blog/development/writing-a-parameterized-test-in-junit-with-examples/) [Development

## How To Use Assert In JUnit With Examples

The JUnit Assert class is what you use to write unit testing assertions in JUnit. Learn more about it in this guide, full of examples.

Read the post](https://coderpad.io/blog/development/how-to-use-assert-in-junit-with-examples/) [Development

## A Simple Guide To TypeORM: What It Is And How To Use It

Considering current languages have object-oriented programming features, most database management systems are based on the relational model, with tables instead of objects. For these reasons, mapping relational objects is very important in development. In this article, you will learn what TypeORM, one of the main tools used today, is.

Read the post](https://coderpad.io/blog/development/a-simple-guide-to-typeorm-what-it-is-and-how-to-use-it/) [Development

## Using PreparedStatement in JDBC With Examples

In this post, we'll see why and how to work with JDBC and PreparedStatement. We will also learn along with examples using code.

Read the post](https://coderpad.io/blog/development/using-preparedstatement-in-jdbc-with-examples/) [Development

## React vs React Native: The Differences Explained

React and React Native are similar in that they both allow web developers to build applications based on the unique concept of components. But the two frameworks do this in radically different ways. In this post, we cover the key differences between react and react native frameworks, implementation, and which is an appropriate choice.

Read the post](https://coderpad.io/blog/development/react-vs-react-native-the-differences-explained/) [Development

## Logging in Django

The most challenging part of fixing a problem is identifying it. Unfortunately, this statement is exceptionally true when it comes to debugging. Learn how to use the power of logging into your Django applications to improve your debug process in this article.

Read the post](https://coderpad.io/blog/development/logging-in-django/)

## Hire with confidence.

See why engineering teams trust CoderPad to evaluate developers with realistic, AI-ready hiring workflows.

[Request a demo](https://coderpad.io/sales/)
