E2e Test 101 Guide: Beyond Unit Tests For Full Coverage

Cover Image for E2E Test 101 Guide: Beyond Unit Tests for Full Coverage
Background

Animesh Pathak

Table of Contents
Table of Contents

There is often a philosophical debate about whether to write a unit test or an e2e test 101. This has been a common question I have encountered many times – when limited in time and resources, what kind of testing should be done? Weighing up such factors can be difficult, especially given that usually only one type can be conducted.

Let’s start with why:

Why do we Test?

The primary objective of tests is to instil confidence that our code functions correctly. By detecting bugs before they impact users, tests act as a protective layer, ensuring the reliability of our software.

When a feature malfunctions, your tests act as detectives, swiftly identifying the root cause. Pinpointing the exact location of the issue allows you to analyze and rectify the problem efficiently. The more precise and granular our tests are in pinpointing issues, the faster we can resolve them.

Unit tests

They are your first line of defence against bugs. A unit test typically has no dependencies, can be executed in milliseconds, and is perfectly reliable and if those units work as expected, It focuses on individual units of work instead of whole applications. The unit of work can be single:

  • function or method,
  • class,
  • module.

Do I need them?

Whether it be a function, a class, or anything else, unit tests are meant to test every feature/potential logical path. When writing unit tests, it is essential to cover every feature and potential logical path of the code, regardless of whether it is a function, a class, or any other component. Achieving 100% code coverage for the unit tests means that every possible flow within the function, class, or module has been thoroughly tested.

However, in reality, achieving 100% code coverage can be quite challenging and may not always be feasible. Realistically, a good target for code coverage is around 80%. This means that approximately 80% of the code is tested, taking into account different scenarios and logical paths.

Mostly E2E Test 101

An end-to-end test is a test that exercises an aspect of the system within the context of the system as a whole. This test not only verifies that the feature works, but also verifies that it works under typical operational conditions.

The end-to-end test is essential, for example, If I want to know that the system I’m delivering meets the requirements and will continue to meet the requirements as the system evolves in the future, It allows me the opportunity to study the application under conditions where these bugs arise and is invaluable for building robust and reliable software systems.

How to write more E2E test 101

E2E tests are complex and difficult to implement. They are most common in production-grade code, so you can probably spare yourself the time on pet projects or schoolwork if manual testing is more efficient. In summary, use E2E tests when:

  • There will be users aside from yourself
  • You have enough infrastructure for a staging or dev environment

How much end-to-end testing is necessary?

When it comes to the issue of how much end-to-end testing to perform, the go-to is often the Test Automation Pyramid. This model shows that a majority of automated tests should be unit tests. These are tiny but fast tests that are executed lower than the user interface layer. Then, there are API/integration tests in between, verifying a combination of elements such as data services, APIs and external services. Finally on top is E2E testing which is generally done through UI control. Thus, this pyramid displays how these kinds of tests should be performed for them to be most effective.

For an accurate picture of the test automation pyramid, Mike Wacker of Google proposed a 70/20/10 split in 2015. This ratio stands for 70% unit tests, 20% integration tests, and 10% automated E2E tests.

Conclusion

I don’t think that anyone can argue that testing software is a waste of time. The biggest challenge is knowing what to test and how to test it in a way that gives true confidence rather than the false confidence of testing implementation details.

Whenever possible, I try to write more E2E test 101 and view unit tests as complimentary to E2E tests. As you move up the pyramid, the confidence quotient of each form of testing increases. So while E2E tests may be slower and more expensive than unit tests, they bring you much more confidence that your application is working as intended.

Overall, it ultimately comes down to whether its purpose/common use cases suit you, and whether their properties (i.e. execution time, required technical infrastructure, etc) are viable for your system.

Author

Author Avatar
Author Details
Author Name: Animesh pathak
Author Description:

  • More Stories

    Cover Image for Canary Testing: A Comprehensive Guide for Developers

    Canary Testing: A Comprehensive Guide for Developers

    Animesh Pathak

    Table of Contents What’s Canary Testing, Anyway? Imagine you’re a miner with a canary in a cage. If the air...

    Cover Image for Mock vs Stub vs Fake: Understand the difference

    Mock vs Stub vs Fake: Understand the difference

    Arindam

    Table of Contents Introduction Testing software is like putting it through a series of challenges to make sure it’s tough...

    Cover Image for Writing test cases for Cron Job Testing

    Writing test cases for Cron Job Testing

    Animesh Pathak

    Table of Contents Understanding Cron Jobs: A Quick Recap Cron is a time-based job scheduler in Unix-like operating systems. It...

    Cover Image for Improving Code Quality and Accelerating Development: The Continuous Testing Way

    Improving Code Quality and Accelerating Development: The Continuous Testing Way

    Prajwal

    Table of Contents Introduction In the fast-changing world of software development, teams struggle to maintain good code quality while shortening...

    Cover Image for Understanding Testing in production

    Understanding Testing in production

    Arindam

    Table of Contents Introduction Testing in production was previously ignored by Product Developers, But recently it gaining Popularity Again! Even,...

    Cover Image for 5 Unit Testing Tools You Must Know in 2024

    5 Unit Testing Tools You Must Know in 2024

    Arindam

    Table of Contents Introduction: Unit testing is one of the most important areas to ensure code coverage and basic testing...

    Cover Image for Exploring Various Protocols : HTTP to Databases

    Exploring Various Protocols : HTTP to Databases

    Shivam

    Table of Contents Table of Contents Unraveling the Mystery of various Protocols The Role of Protocols in Network Communication Examples:...

    Cover Image for Demystifying Cron Job Testing

    Demystifying Cron Job Testing

    Animesh Pathak

    Table of Contents What is Cron Job? Before we dive into the world of testing Cron jobs, let’s first know...

    Cover Image for Building Custom YAML-DSL in Python

    Building Custom YAML-DSL in Python

    Animesh Pathak

    Table of Contents In this blog post, I will guide you through the process of building a custom DSL in...

    Cover Image for eBPF, Service Mesh and Sidecar

    eBPF, Service Mesh and Sidecar

    Animesh Pathak

    Table of Contents The operating system is like the boss of your computer, handling security, networking, and keeping an eye...

    Cover Image for MongoDB in Mock Mode: Acting the Server Part

    MongoDB in Mock Mode: Acting the Server Part

    Ritik

    Table of Contents In the contemporary software development landscape, unit tests have become paramount for ensuring software quality. A prevalent...

    Cover Image for Capture gRPC Traffic going out from a Server

    Capture gRPC Traffic going out from a Server

    Mehfooz

    Table of Contents How does gRPC work? A quick Google search would tell you that it uses HTTP/2.0 under the...

    Cover Image for Integration vs E2E Testing: What worked for me as a charm

    Integration vs E2E Testing: What worked for me as a charm

    Sarthak Shyngle

    Table of Contents When it comes to testing software applications, various testing techniques can be employed. Three common testing methods...

    Cover Image for Automated E2E tests using Property Based Testing  | Part II

    Automated E2E tests using Property Based Testing | Part II

    charan

    Table of Contents If you haven’t visited Part I, I highly recommend you go through it for a better understanding...

    Cover Image for Automated End to End tests using Property Based Testing  | Part I

    Automated End to End tests using Property Based Testing | Part I

    charan

    Table of Contents " Engineers call them edge cases. I call them: what our users do " – Noah Sussman...

    Cover Image for Go Mocks and Stubs generator Made Easy

    Go Mocks and Stubs generator Made Easy

    Jain

    Table of Contents Testing network stuff like APIs and database calls can be a real pain: I find myself burning...