Testing: Do More With Less

Rate this content
Bookmark

How can you be confident that your code is well-tested? For me, the criteria are straightforward: you feel comfortable deploying it automatically to production on a Friday evening, and the release pipeline stays as green as an evergreen tree. In this talk, I'll share some approaches that I am following to hit both targets for Node.js apps (APIs, BFFs, etc).

Eugene Fidelin
Eugene Fidelin
27 min
13 Jun, 2024

Comments

Sign in or register to post your comment.
  • Eugene Fidelin
    Eugene Fidelin
    eBay
    Slides: https://www.slideshare.net/slideshow/testing-do-more-with-less-jsnation-2024/269740608

Video Summary and Transcription

This talk focuses on practical approaches for testing Node.js applications, including the use of Dora metrics and the testing trophy strategy. It emphasizes the importance of covering critical flows with integration and end-to-end tests, while also considering the cost and speed of different test types. The speaker recommends mocking third-party services and using snapshot testing, but warns about the potential for false positives. Playwright is suggested as a preferred tool, and the importance of automated test execution is emphasized.

Available in Español: Pruebas: Haz más con menos

1. Introduction to Testing Node.js Applications

Short description:

My talk is testing do more with less, and it would be some practical approach how you can test your Node.js application. But before many teams reach that, can answer yes on those questions, they need to go through some paths and implement some things. So how do you make sure that you're moving the right direction? So there is so-called Dora metrics, and it stays for DevOps research and something, an A. It has four key metrics, and three of them are directly impacted by good testing.

Hi, everyone. Thanks for coming. My talk is testing do more with less, and it would be some practical approach how you can test your Node.js application.

First, try to answer the question like is your code well tested? But be honest. Do you feel comfortable deploying it automatically on a Friday evening and just going home? Who can raise their hand? Cool. We have some brave people here in the room. Nice. But does your release pipeline always stay as green as your Christmas tree? It's also important. That's cool, guys. Maybe next time we're going to do talk together. I will learn from you.

But before many teams reach that, can answer yes on those questions, they need to go through some paths and implement some things. So how do you make sure that you're moving the right direction? So there is so-called Dora metrics, and it stays for DevOps research and something, an A. It basically helps you to understand how good your team or the company in terms of performance and velocity, so how good you are at shipping software.

It has four key metrics, and three of them are directly impacted by good testing. First is deployment frequency. It basically measures how often your team successfully deploys to production. You can imagine if you have, say, manual testing still yet, I hope not, but some companies still have manual testing, you cannot deploy very often. You probably deploy once every second week or once per month. Ideally, you should deploy on demand. Lead time for change. Testing also has a big impact on this metric because even if you have automated tests, imagine you have very flaky and slow end-to-end tests. It means that whenever you push the master, whenever your deploy pipeline starts, it might take you hours, and if it fails, it might take you days or even weeks to get the green deploy pipeline. So again, you're very slow. And the last but not the least where the test plays an important role is change failure rate. It basically measures how often your deployment causes some production issue, and it has a direct connection with the test coverage. But not the test coverage like you measure, oh, 80% of my lines are covered. I'm happy. No. This is the actual coverage.

2. Optimizing Test Coverage and Approaches

Short description:

The testing trophy helps you focus on writing the right tests. Unit tests have low cost and high speed, while end-to-end tests have high cost and low speed. Integration tests provide good confidence at a moderate cost. Start with writing integration tests and consider writing unit tests for specific cases. Talk to your business and product teams to identify critical flows.

Are you testing the right things? Are you covering the flows that bring the most value to the company? So how you can approach your testing, how you can write less test and get higher confidence. So again, I assume you at least heard, or even maybe you're already applying the testing trophy. So it is advocated and it became popular after Kent C. Dodds I think wrote an article about it and he's doing trainings around it. But basically, the main idea of the testing trophy is to help you to focus on writing the right tests. If you see each test has its cost and gives you some level of confidence, and it has some speed.

So, unit tests, the cost are very low, yeah? It's very easy to write unit tests, especially nowadays we have chat GPT, you can ask and it will generate unit tests for you automatically. They give you, I would say, average confidence because if you only have unit tests, it might not be enough to deploy automatically but the speed is very high. You can execute them faster. On the other end of spectrum, end-to-end tests. The cost for them are very high because it's not only the cost to write the end-to-end test but also to maintain it in the long term. Like you need a special infrastructure, you need special environment where you need to run them, that environment should be stable. But it gives you very high confidence. Like if your end-to-end test is green, you're very confident that everything works as expected, but the speed is low, yeah? So, somewhere in between there are integration tests. So, the cost for them are very close to unit tests, they give you very good confidence. I would say from my experience, only having integration test sometimes is good enough and you can live without end-to-end test and their speed is still high. And you can see that in this testing trophy, it emphasizes that amount of integration test should be, should overcome the amount of end-to-end and unit test.

So, how do you approach this? So, step number zero. You remember? You can enable static linters and type checks. It's free, yeah? Everyone should do it. Step number one. You start with writing integration test. And you try to write integration test for each happy and non-happy flow. And then you check your test coverage. You identify, okay, maybe there are some rear-edge cases for which there is no sense to write an integration test, you can write a unit test to cover them. Or maybe within your application, there are some reusable code that you used across multiple parts. So, maybe you consider it as a library. So, it also makes sense to write unit test for that. And the last, in terms of testing, talk to your business people, talk to your product. Ask them to identify the very few business critical flows.

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
Do you have a large product built by many teams? Are you struggling to release often? Did your frontend turn into a massive unmaintainable monolith? If, like me, you’ve answered yes to any of those questions, this talk is for you! I’ll show you exactly how you can build a micro frontend architecture with Remix to solve those challenges.
Network Requests with Cypress
TestJS Summit 2021TestJS Summit 2021
33 min
Network Requests with Cypress
Top Content
Whether you're testing your UI or API, Cypress gives you all the tools needed to work with and manage network requests. This intermediate-level task demonstrates how to use the cy.request and cy.intercept commands to execute, spy on, and stub network requests while testing your application in the browser. Learn how the commands work as well as use cases for each, including best practices for testing and mocking your network requests.
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
Remix is a web framework that gives you the simple mental model of a Multi-Page App (MPA) but the power and capabilities of a Single-Page App (SPA). One of the big challenges of SPAs is network management resulting in a great deal of indirection and buggy code. This is especially noticeable in application state which Remix completely eliminates, but it's also an issue in individual components that communicate with a single-purpose backend endpoint (like a combobox search for example).
In this talk, Kent will demonstrate how Remix enables you to build complex UI components that are connected to a backend in the simplest and most powerful way you've ever seen. Leaving you time to chill with your family or whatever else you do for fun.
A Framework for Managing Technical Debt
TechLead Conference 2023TechLead Conference 2023
35 min
A Framework for Managing Technical Debt
Top Content
Let’s face it: technical debt is inevitable and rewriting your code every 6 months is not an option. Refactoring is a complex topic that doesn't have a one-size-fits-all solution. Frontend applications are particularly sensitive because of frequent requirements and user flows changes. New abstractions, updated patterns and cleaning up those old functions - it all sounds great on paper, but it often fails in practice: todos accumulate, tickets end up rotting in the backlog and legacy code crops up in every corner of your codebase. So a process of continuous refactoring is the only weapon you have against tech debt.In the past three years, I’ve been exploring different strategies and processes for refactoring code. In this talk I will describe the key components of a framework for tackling refactoring and I will share some of the learnings accumulated along the way. Hopefully, this will help you in your quest of improving the code quality of your codebases.

Making JavaScript on WebAssembly Fast
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
Top Content
JavaScript in the browser runs many times faster than it did two decades ago. And that happened because the browser vendors spent that time working on intensive performance optimizations in their JavaScript engines.Because of this optimization work, JavaScript is now running in many places besides the browser. But there are still some environments where the JS engines can’t apply those optimizations in the right way to make things fast.We’re working to solve this, beginning a whole new wave of JavaScript optimization work. We’re improving JavaScript performance for entirely different environments, where different rules apply. And this is possible because of WebAssembly. In this talk, I'll explain how this all works and what's coming next.

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
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.
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.
API Testing with Postman Workshop
TestJS Summit 2023TestJS Summit 2023
48 min
API Testing with Postman Workshop
Top Content
WorkshopFree
Pooja Mistry
Pooja Mistry
In the ever-evolving landscape of software development, ensuring the reliability and functionality of APIs has become paramount. "API Testing with Postman" is a comprehensive workshop designed to equip participants with the knowledge and skills needed to excel in API testing using Postman, a powerful tool widely adopted by professionals in the field. This workshop delves into the fundamentals of API testing, progresses to advanced testing techniques, and explores automation, performance testing, and multi-protocol support, providing attendees with a holistic understanding of API testing with Postman.
1. Welcome to Postman- Explaining the Postman User Interface (UI)2. Workspace and Collections Collaboration- Understanding Workspaces and their role in collaboration- Exploring the concept of Collections for organizing and executing API requests3. Introduction to API Testing- Covering the basics of API testing and its significance4. Variable Management- Managing environment, global, and collection variables- Utilizing scripting snippets for dynamic data5. Building Testing Workflows- Creating effective testing workflows for comprehensive testing- Utilizing the Collection Runner for test execution- Introduction to Postbot for automated testing6. Advanced Testing- Contract Testing for ensuring API contracts- Using Mock Servers for effective testing- Maximizing productivity with Collection/Workspace templates- Integration Testing and Regression Testing strategies7. Automation with Postman- Leveraging the Postman CLI for automation- Scheduled Runs for regular testing- Integrating Postman into CI/CD pipelines8. Performance Testing- Demonstrating performance testing capabilities (showing the desktop client)- Synchronizing tests with VS Code for streamlined development9. Exploring Advanced Features - Working with Multiple Protocols: GraphQL, gRPC, and more
Join us for this workshop to unlock the full potential of Postman for API testing, streamline your testing processes, and enhance the quality and reliability of your software. Whether you're a beginner or an experienced tester, this workshop will equip you with the skills needed to excel in API testing with Postman.
Node.js Masterclass
Node Congress 2023Node Congress 2023
109 min
Node.js Masterclass
Top Content
Workshop
Matteo Collina
Matteo Collina
Have you ever struggled with designing and structuring your Node.js applications? Building applications that are well organised, testable and extendable is not always easy. It can often turn out to be a lot more complicated than you expect it to be. In this live event Matteo will show you how he builds Node.js applications from scratch. You’ll learn how he approaches application design, and the philosophies that he applies to create modular, maintainable and effective applications.

Level: intermediate