Effective Testing Approaches for your Application

Cecelia Martinez

Refactr.Tech 2021

@ceceliacreates

Testing is the best way to understand your application.

Bad code can’t hide from good testing.

Before you can decide what approach to take with your testing strategy, you have to define the primary goal(s) for your test suite.

Testing Goals

  • Ensure the business logic of your app is airtight
  • Validate that components behave and render appropriately
  • Make sure the different parts of your app work together
  • Confirm the application looks as expected
  • Ensure the application works for your user
  • Prevent bugs/regressions in production
  • Reduce developer time spent on debugging
  • Have confidence in deployments

Different types of testing achieve different goals.

Goal:

Ensure the business logic of your app is airtight

Unit tests cover individual units of your code.
✅  API tests cover endpoint functionality.

  • Typically easy and fast to write

  • Can address edge cases that are hard to replicate in production

  • A lot of tests required for full application coverage

  • No guarantee the individual units will work together

Goal:

Make sure the different parts of your app work together

✅ Integration tests cover the relationship between parts of your code.
✅  Contract testing covers your application’s connection to external APIs or microservices.

  • Confirm important implementations function as expected

  • Ensures changes in one part of the application don’t break another area

  • Useful for critical functionality of the application

Goal:

Validate that components behave and render appropriately

✅ Component tests cover the components of your application, ensuring they handle different props appropriately and render as expected.

  • Particularly critical for multi-use components leveraged across your application

  • Relevant for modern component-based frameworks like React, Angular, and Vue

  • Don't address user flows across components

Goals:

  • Confirm the application looks as expected

  • Ensure the application works for your user

  • Prevent bugs/regressions in production

  • Reduce developer time spent on debugging

  • Have confidence in deployments

✅ Visual and functional end-to-end tests cover your application like a user would.

“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.”

 

- Kent C. Dodds (https://kentcdodds.com/blog/write-tests)

  • Can achieve high application coverage with fewer tests

  • Check application functionality and appearance at the same time with visual testing tools

  • Keep your user happy and critical application paths working

  • Modern tooling makes writing end-to-end tests faster and easier

✅ Visual and functional end-to-end tests cover your application like a user would.

Different types of testing achieve different goals.

Structure your test suite based on your goals 🏅

Test Coverage

  • Code coverage
  • Case coverage

“If you don’t feel confident pushing the release button, write more tests.”

- Gil Tayar

twitter.com/giltayar

 

Effective Testing Approaches for your Application

Cecelia Martinez

Refactr.Tech 2021

@ceceliacreates

Effective Testing Approaches for your Application

By Cecelia Martinez

Effective Testing Approaches for your Application

Unit, component, integration, end-to-end-- there are many types of testing you can use when developing and releasing an application. You may have also heard of the testing pyramid, trophy, and even crab, which all demonstrate approaches for prioritizing test types. In this talk, we'll define the different types of testing and cover their use cases, as well as provide some guidelines for deciding which approach to use for your application. From Refactr.TECH 2021.

  • 2,187