Welcome!

Microservices Expo Authors: Zakia Bouachraoui, Pat Romanski, Elizabeth White, Liz McMillan, 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
When building large, cloud-based applications that operate at a high scale, it’s important to maintain a high availability and resilience to failures. In order to do that, you must be tolerant of failures, even in light of failures in other areas of your application. “Fly two mistakes high” is an old adage in the radio control airplane hobby. It means, fly high enough so that if you make a mistake, you can continue flying with room to still make mistakes. In his session at 18th Cloud Expo, Lee A...
Lori MacVittie is a subject matter expert on emerging technology responsible for outbound evangelism across F5's entire product suite. MacVittie has extensive development and technical architecture experience in both high-tech and enterprise organizations, in addition to network and systems administration expertise. Prior to joining F5, MacVittie was an award-winning technology editor at Network Computing Magazine where she evaluated and tested application-focused technologies including app secu...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
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 ...
Modern software design has fundamentally changed how we manage applications, causing many to turn to containers as the new virtual machine for resource management. As container adoption grows beyond stateless applications to stateful workloads, the need for persistent storage is foundational - something customers routinely cite as a top pain point. In his session at @DevOpsSummit at 21st Cloud Expo, Bill Borsari, Head of Systems Engineering at Datera, explored how organizations can reap the bene...
Using new techniques of information modeling, indexing, and processing, new cloud-based systems can support cloud-based workloads previously not possible for high-throughput insurance, banking, and case-based applications. In his session at 18th Cloud Expo, John Newton, CTO, Founder and Chairman of Alfresco, described how to scale cloud-based content management repositories to store, manage, and retrieve billions of documents and related information with fast and linear scalability. He addresse...
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...
SYS-CON Events announced today that DatacenterDynamics has been named “Media Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY. DatacenterDynamics is a brand of DCD Group, a global B2B media and publishing company that develops products to help senior professionals in the world's most ICT dependent organizations make risk-based infrastructure and capacity decisions.
Discussions of cloud computing have evolved in recent years from a focus on specific types of cloud, to a world of hybrid cloud, and to a world dominated by the APIs that make today's multi-cloud environments and hybrid clouds possible. In this Power Panel at 17th Cloud Expo, moderated by Conference Chair Roger Strukhoff, panelists addressed the importance of customers being able to use the specific technologies they need, through environments and ecosystems that expose their APIs to make true ...
In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...