Welcome!

Microservices Expo Authors: Liz McMillan, Pat Romanski, Elizabeth White, Mehdi Daoudi, Yeshim Deniz

Related Topics: Microservices Expo, Industrial IoT

Microservices Expo: Article

The Difference Between Unit Testing and Integration Testing

This article will discuss how to prevent your unit tests turning into integration tests.

This article was written by Gil Zilberfeld, Product Manager, Typemock.

First things first:

What is a unit test?

A unit test is:

  • Repeatable: You can rerun the same test as many times as you want.
  • Consistent: Every time you run it, you get the same result. (for example: Using threads can produce an inconsistent result)
  • In Memory: It has no "hard" dependencies on anything not in memory (such as file system, databases, network)
  • Fast: It should take less than half a second to run a unit test.
  • Checking one single concern or "use case" in the system: (More than one can make it harder to understand what or where the problem is when the problem arises.)

By breaking any of these guidelines, you increase the chance of developers either not trusting or not believing the test results (due to repeated false failures by the tests), or people not wanting to run the tests at all because they run too slowly.

What is an integration test?
An integration test is any test that can't be described as a unit test. The different kinds of integration tests (performance tests, system tests, acceptance tests etc.) are not the subject of this piece. Our main concern here is just differentiating unit tests from everything else.

An integration test might:

  • Use system dependent values that change dynamically (such as DateTime.Now, or Environment.MachineName)
  • Create objects of which it has little control (such as threads, random number generators)
  • Reach out to external systems or local machine dependencies (from calling web services to using local configuration files)
  • Test multiple things in the course of one test case (from database integrity, to configurations, to protocols, to system logic, in one go).

Taking those bullets into account, we can say that Integration tests will most likely:

  • Be much slower than unit tests
  • Be much harder or time consuming to recreate and run fully
  • Collecting the test result might be more problematic

When do integration tests make sense?
Integration tests can make a lot of sense in most systems in two particular configurations:

  • Written as an additional layer of regression testing beyond unit tests
  • In legacy code situations, written before unit tests or refactoring can be done

Additional regression test layer
Integration tests can serve as an extra "smoke test" that can be run when the full system needs to be tested , proving that deployment of all the system components works well, for example. With those kinds of tests, you would test many small things in one large test case.

Integration tests on legacy code
Michael Feathers, in his book "Working Effectively with Legacy Code" defined legacy code as "code that does not have tests." It's usually hard or impossible to write unit tests for such code, as it is mostly untestable. Tools like Typemock Isolator help relieve that problem by being able to fake anything, and integration tests can serve as an additional smoke test to make sure you didn't break the integration between system components, one level above unit tests.

Summary
By being able to distinguish unit from non-unit tests, we can make sure they are separated in our projects, and give our developers a "safe green zone" (as mentioned in Roy Osherove's book ‘The Art of Unit Testing') that contains only unit tests, in which developers can run and always trust the results.

•   •   •

With over 15 years of experience in software development, Gil has worked with a range of aspects of software development, from coding to team management, and implementation of processes. Gil presents, blogs and talks about unit testing, and encourages developers from beginners to experienced, to implement unit testing as a core practice in their projects. Gil writes a personal blog (http://www.gilzilberfeld.com), and contributes to the Typemock blog - http://blog.typemock.com/

More Stories By Josh Litvin

Yaniv Yehuda is the Co-Founder and CTO of DBmaestro, an Enterprise Software Development Company focusing on database development and deployment technologies. Yaniv is also the Co-Founder and the head of development for Extreme Technology, an IT service provider for the Israeli market. Yaniv was a captain in Mamram, the Israel Defense Forces computer centers where he served as a software engineering manager.

Microservices Articles
The explosion of new web/cloud/IoT-based applications and the data they generate are transforming our world right before our eyes. In this rush to adopt these new technologies, organizations are often ignoring fundamental questions concerning who owns the data and failing to ask for permission to conduct invasive surveillance of their customers. Organizations that are not transparent about how their systems gather data telemetry without offering shared data ownership risk product rejection, regu...
Containers and Kubernetes allow for code portability across on-premise VMs, bare metal, or multiple cloud provider environments. Yet, despite this portability promise, developers may include configuration and application definitions that constrain or even eliminate application portability. In this session we'll describe best practices for "configuration as code" in a Kubernetes environment. We will demonstrate how a properly constructed containerized app can be deployed to both Amazon and Azure ...
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm. In their Day 3 Keynote at 20th Cloud Expo, Chris Brown, a Solutions Marketing Manager at Nutanix, and Mark Lav...
The now mainstream platform changes stemming from the first Internet boom brought many changes but didn’t really change the basic relationship between servers and the applications running on them. In fact, that was sort of the point. In his session at 18th Cloud Expo, Gordon Haff, senior cloud strategy marketing and evangelism manager at Red Hat, will discuss how today’s workloads require a new model and a new platform for development and execution. The platform must handle a wide range of rec...
The Internet of Things is clearly many things: data collection and analytics, wearables, Smart Grids and Smart Cities, the Industrial Internet, and more. Cool platforms like Arduino, Raspberry Pi, Intel's Galileo and Edison, and a diverse world of sensors are making the IoT a great toy box for developers in all these areas. In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists discussed what things are the most important, which will have the most profound e...
If your cloud deployment is on AWS with predictable workloads, Reserved Instances (RIs) can provide your business substantial savings compared to pay-as-you-go, on-demand services alone. Continuous monitoring of cloud usage and active management of Elastic Compute Cloud (EC2), Relational Database Service (RDS) and ElastiCache through RIs will optimize performance. Learn how you can purchase and apply the right Reserved Instances for optimum utilization and increased ROI.
TCP (Transmission Control Protocol) is a common and reliable transmission protocol on the Internet. TCP was introduced in the 70s by Stanford University for US Defense to establish connectivity between distributed systems to maintain a backup of defense information. At the time, TCP was introduced to communicate amongst a selected set of devices for a smaller dataset over shorter distances. As the Internet evolved, however, the number of applications and users, and the types of data accessed and...
Consumer-driven contracts are an essential part of a mature microservice testing portfolio enabling independent service deployments. In this presentation we'll provide an overview of the tools, patterns and pain points we've seen when implementing contract testing in large development organizations.
In his session at 19th Cloud Expo, Claude Remillard, Principal Program Manager in Developer Division at Microsoft, contrasted how his team used config as code and immutable patterns for continuous delivery of microservices and apps to the cloud. He showed how the immutable patterns helps developers do away with most of the complexity of config as code-enabling scenarios such as rollback, zero downtime upgrades with far greater simplicity. He also demoed building immutable pipelines in the cloud ...
You have great SaaS business app ideas. You want to turn your idea quickly into a functional and engaging proof of concept. You need to be able to modify it to meet customers' needs, and you need to deliver a complete and secure SaaS application. How could you achieve all the above and yet avoid unforeseen IT requirements that add unnecessary cost and complexity? You also want your app to be responsive in any device at any time. In his session at 19th Cloud Expo, Mark Allen, General Manager of...