---
title: "Should you write unit tests or integration tests?"
url: "https://osherove.com/blog/2014/7/11/should-you-write-unit-tests-or-integration-tests.md"
canonical: "https://osherove.com/blog/2014/7/11/should-you-write-unit-tests-or-integration-tests.html"
published: "2014-07-11T08:22:51"
updated: "2014-07-11T08:22:51"
tags: ["Unit Testing"]
author: "Roy Osherove"
description: "I got this question in the mail. I thought it was quite valid for many other people: Question: Trying to promote unit tests in a new work place: the “search” action from the UI goes through IOC container which calls a…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Should you write unit tests or integration tests?

By Roy Osherove July 11, 2014 In [Unit Testing](https://osherove.com/blog/category/unit-testing)

**Historical article** · Originally published July 11, 2014; technical details may be outdated.

I got this question in the mail. I thought it was quite valid for many other people:

### Question:

Trying to promote unit tests in a new work place: the “search” action from the UI goes through IOC container which calls a WCF service, where the search itself is done using entity framework auto generated code.

My colleague claims that due to the multiple dependencies, it doesn’t make sense to fake everything when running the unit test, and it makes more sense to do integration tests in this case.

Is my hunch correct? Should I put efforts into implementing unit tests in this complex scenario?

### My Answer:

You can go either way.

It really depends on time tradeoffs

1. How long will it take to write the tests? For integration tests you will have to wait until the whole system is complete to get the tests even failing, unless you start from a webpage, and then they will fail for as long as the entire system of layers is not built.
2. How long does it take to run and get feedback? integration tests take longer to run usually. and are more complicated to setup. But when they pass you get a good sense of confidence that all the parts work nicely with each other. with unit tests you will get faster feedback, but you will still need those integration tests for full system confidence. On the other hand with integration tests and no unit tests the developers will have to wait in long cycles before they know if they broke something.

There is no one answer. I usually do a mix of both. For web systems I might even start with acceptance tests that fail, and then fill the system slowly with unit tests for parts of the features with more focused functionality. 

I guess you can change the question to : **What type of tests should we write FIRST?**

Only you know that. it changes for every project and system.

## More in Unit Testing

[All posts in Unit Testing](https://osherove.com/blog/category/unit-testing)

- Oct 25, 2014

    ### [What's new and Changed in the Art of Unit Testing 2nd Edition](https://osherove.com/blog/2014/10/25/whats-new-and-changed-in-the-art-of-unit-testing-2nd-edition.html)

- Oct 14, 2013

    ### [Video - Refactoring and Design Skills for Test Driven Development](https://osherove.com/blog/2013/10/14/video-refactoring-and-design-skills-for-test-driven-developm.html)

- Jun 4, 2013

    ### [Ugly Code Means Your Product Used to be Successful](https://osherove.com/blog/2013/6/4/ugly-code-means-your-product-used-to-be-successful.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
