Overtesting: why it happens and how to avoid it

Rate this content
Bookmark
The video talk addresses overtesting, a common issue in software development where excessive time is spent on maintaining test suites rather than on actual application code. It explains that overtesting often results in redundant tests that don't significantly improve code quality. The talk is aimed at both developers and QA teams, offering strategies to improve testing productivity. It suggests breaking down tests into functional units and using techniques like 'expect object containing' to make tests more manageable. The goal is to spend less time on test suites while maintaining 100% coverage. The talk also emphasizes the importance of keeping an open mind about testing practices and regularly evaluating the time spent on test suites versus application code. For effective unit testing practices, viewers are recommended to check out the second edition of Mastering React, test driven development.

From Author:

Overtesting is a common problem with unit test suites. It's when you have too many tests that break often and take up a large amount of time to keep green. Here's a fresh perspective on why that happens and how you can avoid it.

This talk has been presented at TestJS Summit 2022, check out the latest edition of this Tech Conference.

FAQ

Overtesting occurs when too much time is spent on maintaining test suites relative to actual application code, often resulting in excessive and redundant tests that do not significantly improve code quality or reliability.

Both developers and QA engineers or teams can benefit from understanding overtesting to enhance their testing strategies and improve overall productivity in software development.

Some teams spend up to 75% or more of their time on test suites, which is often considered excessive and can detract from time spent on developing new features or fixing bugs in the application code.

The ideal scenario is that only one automated test fails when there is a genuine issue with the code, effectively raising the flag to prevent merging the faulty code without overwhelming developers with multiple failing tests.

A practical approach to reduce overtesting includes breaking down tests into more functional units, focusing on the most critical aspects of the application, and using techniques like 'expect object containing' to make test suites less brittle and more manageable.

Keeping an open mind helps in adopting new ideas and practices that might be more effective, avoiding stagnation and improving the efficiency and effectiveness of testing in software development.

Improving productivity can be achieved by regularly evaluating the time spent on test suites versus application code, identifying areas of redundancy, and implementing more streamlined and targeted testing approaches.

Daniel Irvine
Daniel Irvine
7 min
03 Nov, 2022

Comments

Sign in or register to post your comment.

Video Transcription

1. Introduction to Overtesting

Short description:

Hello, this is a talk about overtesting, which is a simple technique to improve your test suites and testing proficiency. It's aimed at developers and QA teams who want to discuss testing strategies. Spending excessive time on maintaining test suites is a common problem. The goal is to spend equal or less time on test suites while maintaining 100% coverage. The key question is how many automated tests are needed for CI to fail. Over testing occurs when there are too many tests giving the same information.

Hello, this is a talk about overtesting, which is a very, you can probably understand what it is from the name, but it's a simple technique you can use to improve your test suites, improve your testing proficiency, so it's a model for thinking about your testing, really.

And this talk is aimed at developers, but it's also useful for QA engineers, QA teams who want to maybe discuss with their developers their testing strategies, their testing ideas.

So key question by overtesting, and this might be really obvious, but how much time do you spend maintaining your test suites versus your application code? A lot of my clients I've worked with, their problem isn't under testing, they're not testing too few of their use cases, they're actually testing a lot. And so what they end up doing is spending most of their time, I've observed this, up to 75% of their time or more in their test code, making the code changes to their application to add new features or fix bugs, but then having to go back and fix the tests, all these broken tests everywhere.

75% is too much. I love tests, I'm writing test left, right and center, but I'm not wanting to spend my life in the tests. I want to be at least in a situation where I'm spending an equal amount of time on both. And maybe even less, maybe I can be spending less time on my test suites, but still maintaining 100% coverage, for example. So, I'm not going to suggest what that number should be, but if you're kind of in this 75% territory, and you can think about whether you are personally and on your team, but you probably want to be moving down to improve your productivity.

So, here's a simple question. The top screenshot is showing GitHub workflow that's running a pull request. So, I'm sure a lot of you will be familiar with this setup. The red X is showing that CI has failed. So, continuous integration. Like I said, I don't see teams that don't have CI. I think most people are writing tests. Problem isn't under testing, it's over testing. So, to me, this question is key. How many automated tests do you need for CI to fail? The answer is just one. You need one test. So, ideally, whatever change you could make, if there was an issue with that piece of code you've written, just one test would fail because that's all you need to raise the flag and stop your pull request being merged. This is an ideal scenario. I don't think you'd ever get to one. But if you think about the times that this does happen, how many tests are failing for you? Are you in this scenario where multiple test suites are failing, hundreds of tests are failing because of a simple change you made? And this is the scenario where you then start spending that 75% of time fixing your test. So, over testing, very simply, you have too many tests, telling you the same thing. I'm gonna show a very quick example. There's plenty of examples of this. This is one I see a lot, where people are kind of doing scenario-based testing. And what they'll do is they'll set up the test and they'll print out the� they'll have an expectation for the entire response or payload that they've got here. So, this example is just calling fetch and I'm checking the method, credentials, headers, and the body.

2. Improving Test Suite Efficiency

Short description:

Split your tests into different functional units. Use expect object containing for more manageable expectations. Consider how much time you spend in your test code and find ways to improve productivity. Check out the second edition of Mastering React, test driven development, for effective unit testing practices. Have an open mind to new ideas and prioritize ease of testing and time spent.

But what I can do is split this test out into three different tests. The test on the left here is the key one, that's the body, that's probably the thing we're most interested in and the thing in our application code that will change the most. The two tests on the right, these are going to change less often. So, I shouldn't expect these to break. I'm not going to be changing the methods or headers often. So, these should hopefully just remain as they are. They're less brittle now.

The key here is using expect object containing. So, this is definitely your friend. You can make more use of this. Rather doing these huge expectations in your test, break them down into the functional units. So, that's it. That's really the idea. It's about thinking about how much time are you spending in your test code. That's an observation. You start thinking about that, and how does it make you feel? Are you frustrated by this? Rather than just being involved in that moment of fixing a test, getting the build working, stop and think how can you be more productive? And then figure out ways to improve it.

I don't want to suggest too many ways for you to improve things. This is the second edition of this that's just been released. Mastering React, test driven development. This is not just about TDD, it's about good unit testing practices that have helped me in my career. I recommend you check it out if you're interested in figuring out ways of writing tests that won't take up all your time. So to conclude, observation. Think about the time and feeling you've got with your test suite and what's serving you well. You should be happy with your test suites. They should be helping you out. Have an open mind to new ideas. Don't shut down ideas because you've read a blog post that this is a terrible thing to do, you shouldn't do that, this is how you should write tests. Don't write tests like this. Just keep an open mind on the ideas and always come back to the idea of how easy are your tests, how much time you spend in them, how do you feel when you're working in them. And that's it. Thank you very much for listening.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
This talk discusses the usage of Microfrontends in Remix and introduces the Tiny Frontend library. Kazoo, a used car buying platform, follows a domain-driven design approach and encountered issues with granular slicing. Tiny Frontend aims to solve the slicing problem and promotes type safety and compatibility of shared dependencies. The speaker demonstrates how Tiny Frontend works with server-side rendering and how Remix can consume and update components without redeploying the app. The talk also explores the usage of micro frontends and the future support for Webpack Module Federation in Remix.
Network Requests with Cypress
TestJS Summit 2021TestJS Summit 2021
33 min
Network Requests with Cypress
Top Content
Cecilia Martinez, a technical account manager at Cypress, discusses network requests in Cypress and demonstrates commands like cydot request and SCI.INTERCEPT. She also explains dynamic matching and aliasing, network stubbing, and the pros and cons of using real server responses versus stubbing. The talk covers logging request responses, testing front-end and backend API, handling list length and DOM traversal, lazy loading, and provides resources for beginners to learn Cypress.
Testing Pyramid Makes Little Sense, What We Can Use Instead
TestJS Summit 2021TestJS Summit 2021
38 min
Testing Pyramid Makes Little Sense, What We Can Use Instead
Top Content
Featured Video
Gleb Bahmutov
Roman Sandler
2 authors
The testing pyramid - the canonical shape of tests that defined what types of tests we need to write to make sure the app works - is ... obsolete. In this presentation, Roman Sandler and Gleb Bahmutov argue what the testing shape works better for today's web applications.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
RemixConf EU discussed full stack components and their benefits, such as marrying the backend and UI in the same file. The talk demonstrated the implementation of a combo box with search functionality using Remix and the Downshift library. It also highlighted the ease of creating resource routes in Remix and the importance of code organization and maintainability in full stack components. The speaker expressed gratitude towards the audience and discussed the future of Remix, including its acquisition by Shopify and the potential for collaboration with Hydrogen.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
Making JavaScript on WebAssembly Fast
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
Top Content
WebAssembly enables optimizing JavaScript performance for different environments by deploying the JavaScript engine as a portable WebAssembly module. By making JavaScript on WebAssembly fast, instances can be created for each request, reducing latency and security risks. Initialization and runtime phases can be improved with tools like Wiser and snapshotting, resulting in faster startup times. Optimizing JavaScript performance in WebAssembly can be achieved through techniques like ahead-of-time compilation and inline caching. WebAssembly usage is growing outside the web, offering benefits like isolation and portability. Build sizes and snapshotting in WebAssembly depend on the application, and more information can be found on the Mozilla Hacks website and Bike Reliance site.

Workshops on related topic

Designing Effective Tests With React Testing Library
React Summit 2023React Summit 2023
151 min
Designing Effective Tests With React Testing Library
Top Content
Featured Workshop
Josh Justice
Josh Justice
React Testing Library is a great framework for React component tests because there are a lot of questions it answers for you, so you don’t need to worry about those questions. But that doesn’t mean testing is easy. There are still a lot of questions you have to figure out for yourself: How many component tests should you write vs end-to-end tests or lower-level unit tests? How can you test a certain line of code that is tricky to test? And what in the world are you supposed to do about that persistent act() warning?
In this three-hour workshop we’ll introduce React Testing Library along with a mental model for how to think about designing your component tests. This mental model will help you see how to test each bit of logic, whether or not to mock dependencies, and will help improve the design of your components. You’ll walk away with the tools, techniques, and principles you need to implement low-cost, high-value component tests.
Table of contents- The different kinds of React application tests, and where component tests fit in- A mental model for thinking about the inputs and outputs of the components you test- Options for selecting DOM elements to verify and interact with them- The value of mocks and why they shouldn’t be avoided- The challenges with asynchrony in RTL tests and how to handle them
Prerequisites- Familiarity with building applications with React- Basic experience writing automated tests with Jest or another unit testing framework- You do not need any experience with React Testing Library- Machine setup: Node LTS, Yarn
Master JavaScript Patterns
JSNation 2024JSNation 2024
145 min
Master JavaScript Patterns
Featured Workshop
Adrian Hajdin
Adrian Hajdin
During this workshop, participants will review the essential JavaScript patterns that every developer should know. Through hands-on exercises, real-world examples, and interactive discussions, attendees will deepen their understanding of best practices for organizing code, solving common challenges, and designing scalable architectures. By the end of the workshop, participants will gain newfound confidence in their ability to write high-quality JavaScript code that stands the test of time.
Points Covered:
1. Introduction to JavaScript Patterns2. Foundational Patterns3. Object Creation Patterns4. Behavioral Patterns5. Architectural Patterns6. Hands-On Exercises and Case Studies
How It Will Help Developers:
- Gain a deep understanding of JavaScript patterns and their applications in real-world scenarios- Learn best practices for organizing code, solving common challenges, and designing scalable architectures- Enhance problem-solving skills and code readability- Improve collaboration and communication within development teams- Accelerate career growth and opportunities for advancement in the software industry
How to Start With Cypress
TestJS Summit 2022TestJS Summit 2022
146 min
How to Start With Cypress
Featured WorkshopFree
Filip Hric
Filip Hric
The web has evolved. Finally, testing has also. Cypress is a modern testing tool that answers the testing needs of modern web applications. It has been gaining a lot of traction in the last couple of years, gaining worldwide popularity. If you have been waiting to learn Cypress, wait no more! Filip Hric will guide you through the first steps on how to start using Cypress and set up a project on your own. The good news is, learning Cypress is incredibly easy. You'll write your first test in no time, and then you'll discover how to write a full end-to-end test for a modern web application. You'll learn the core concepts like retry-ability. Discover how to work and interact with your application and learn how to combine API and UI tests. Throughout this whole workshop, we will write code and do practical exercises. You will leave with a hands-on experience that you can translate to your own project.
Integrating LangChain with JavaScript for Web Developers
React Summit 2024React Summit 2024
92 min
Integrating LangChain with JavaScript for Web Developers
Featured Workshop
Vivek Nayyar
Vivek Nayyar
Dive into the world of AI with our interactive workshop designed specifically for web developers. "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" offers a unique opportunity to bridge the gap between AI and web development. Despite the prominence of Python in AI development, the vast potential of JavaScript remains largely untapped. This workshop aims to change that.Throughout this hands-on session, participants will learn how to leverage LangChain—a tool designed to make large language models more accessible and useful—to build dynamic AI agents directly within JavaScript environments. This approach opens up new possibilities for enhancing web applications with intelligent features, from automated customer support to content generation and beyond.We'll start with the basics of LangChain and AI models, ensuring a solid foundation even for those new to AI. From there, we'll dive into practical exercises that demonstrate how to integrate these technologies into real-world JavaScript projects. Participants will work through examples, facing and overcoming the challenges of making AI work seamlessly on the web.This workshop is more than just a learning experience; it's a chance to be at the forefront of an emerging field. By the end, attendees will not only have gained valuable skills but also created AI-enhanced features they can take back to their projects or workplaces.Whether you're a seasoned web developer curious about AI or looking to expand your skillset into new and exciting areas, "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" is your gateway to the future of web development. Join us to unlock the potential of AI in your web projects, making them smarter, more interactive, and more engaging for users.
Detox 101: How to write stable end-to-end tests for your React Native application
React Summit 2022React Summit 2022
117 min
Detox 101: How to write stable end-to-end tests for your React Native application
Top Content
WorkshopFree
Yevheniia Hlovatska
Yevheniia Hlovatska
Compared to unit testing, end-to-end testing aims to interact with your application just like a real user. And as we all know it can be pretty challenging. Especially when we talk about Mobile applications.
Tests rely on many conditions and are considered to be slow and flaky. On the other hand - end-to-end tests can give the greatest confidence that your app is working. And if done right - can become an amazing tool for boosting developer velocity.
Detox is a gray-box end-to-end testing framework for mobile apps. Developed by Wix to solve the problem of slowness and flakiness and used by React Native itself as its E2E testing tool.
Join me on this workshop to learn how to make your mobile end-to-end tests with Detox rock.
Prerequisites- iOS/Android: MacOS Catalina or newer- Android only: Linux- Install before the workshop
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
React Day Berlin 2022React Day Berlin 2022
86 min
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
Top Content
WorkshopFree
Hussien Khayoon
Kahvi Patel
2 authors
Using a library might seem easy at first glance, but how do you choose the right library? How do you upgrade an existing one? And how do you wade through the documentation to find what you want?
In this workshop, we’ll discuss all these finer points while going through a general example of building a code editor using CodeMirror in React. All while sharing some of the nuances our team learned about using this library and some problems we encountered.