DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. The perils of long-running test suites

The perils of long-running test suites

Giorgio Sironi user avatar by
Giorgio Sironi
·
Oct. 24, 12 · Interview
Like (0)
Save
Tweet
Share
5.95K Views

Join the DZone community and get the full member experience.

Join For Free
Long-running test suites take more than N minutes to run on an ordinary development machine, where N is in a range from 5 to 20-30, depending on your tolerance. Such long build times are not uncommon but they may holding you back from fast delivery and feedback.

The dangers

First of all, automated test suites are part of the commit and integration process. This means they are run before every remote commit (your code leaves your machine and gets integrated in the main branch.)

Chances are that the suite is also part of the deployment pipeline, an automated sequence of tasks that packages up your code into binaries or archives (for interpreted code), tests it in every way known to man and ships it to a Quality Assurance machine and then to the production environment. The deployment pipeline concept is treated in the Continuous Delivery book.

So what if your suite takes 20 minutes to run?

  • A commit is a dreaded occasion. No one wants to take a coffee waiting for the suite, so people will either commit without running it, or make giant commits at the end of a day of work.
  • The Continuous Integration system picks up multiple commits at every new job, because between runs more than one commit is performed. A failure cannot be fixed with a single revert.
  • The load on the CI machine increases and slows down other projects.
  • The integration time increases: to be sure you have integrated your code, you have to wait not only for the test suite to finish on your machine, but also for the same result to come out from CI. That's a minimum of 2 times the suite execution time, so don't go around telling people to integrate more often*link in these conditions or it will be the only thing they do in their day.
  • If you want to test or run something in the late stages of the pipeline, like a QA machine, you'll have a slow feedback system that means you only have a limited number of change sets that you can get to QA every day.
  • The feedback from production is slowed down in the same way. You can never fully reproduce the production environment, even if we usually have a good model of it. Tests can cover all of the code but not every execution path, and therefore can only prove the presence of bugs, not their absence. If you really broke a feature in production, would you like to know it 10 minutes after your commit, or after an hour, so that it's not clear which change has caused it?

The solutions

For the benefit of all of us that encounter a slow test suite, I put together a  series of ideas to speed you up.

Improvements can be made over the whole build process, but some are language-dependent (e.g. incremental compilation), so I'll stick to the ones applicable to xUnit test suites.

  • Test profiling and optimization. xUnit frameworks (JUnit, or PHPUnit) can produce an XML output that contains the execution times measured for each single test. Take a look at the 10 tests with highest execution time, and simplify or delete those ones if they do not provide a good value/cost ratio.
  • Test deletion. Tests may be redundant, especially when developed after the code and without a clear picture of the responsibilities of the SUT.
  • Test substitution. Test a behavior at the unit level instead of going through the whole system; for example, tests that internally rely on Apache or MySQL processes may substitute a Test Double for the http- or database-accessing code.
  • Fakes. If the system interacts with Test Double many times, provide a low-overhead implementation of the external system. A classic solution for testing queries: instead of going mad by stubbing fixed results for everyone of them, provide a Sqlite instance instead of the MySQL real one and execute them over there.
  • Caching. In some projects, the database schema can be reused between tests or between commits. In other, even a basic data set that populates it can be recycled between tests. Test isolation is sacred, but test speed is not much down in the list.
  • Divide the test suite in multiple stages: unit tests, functional and end-to-end tests, integration with other systems. If the unit tests suite fails, fail the build; otherwise mark it as green and go on to the next stage.
  • If all else fails, separate the current project in multiple ones (different Bounded Contexts) that can evolve independently. Their suites will be smaller, and the feedback rate in each of them will increase accordingly; for example, if you divide a project with a test suite than runs in T in half, you can get features in production on both of the new components in T/2.

Conclusions

You don't have to accept hour-long build and test execution times. It's a form of technical debt that you can fight to improve the feedback rate of the build: the sooner a build fails or pass, the less time you wait to choose between reworking a feature, monitoring it in production, or go on to the next story.

unit test Continuous Integration/Deployment Commit (data management) Test suite

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Kubernetes-Native Development With Quarkus and Eclipse JKube
  • Seamless Integration of Azure Functions With SQL Server: A Developer's Perspective
  • How To Perform Local Website Testing Using Selenium And Java
  • Navigating Progressive Delivery: Feature Flag Debugging Common Challenges and Effective Resolution

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: