Photo by Eric Er on Unsplash

On this page

Types of tests

  • Unit Tests test very specific, low-level pieces of functionality for example if a function returns the expected value.
  • Integration Tests ensure that the individual pieces of your application work together correctly. For example if a method invocation successfully calls an API which in turn stores a value in the database.Single-service integration Tests test a single piece or service of your application end to end, independent of the other pieces. For example, to test our server API code we would mock the database and use an integration testing framework to make calls to the API instead of the front-end. The bad thing is that this approach is susceptible to outside changes, in other words: If the database API changes then the server API tests would still pass, because we mocked them out.
  • Boundary Integration Tests test the communication between different pieces of your application. For example testing that the front-end is calling the server API correctly, or that the server API is calling the database API correctly. Don’t use test doubles for this. Disadvantage is that tests run slower.
  • End-to-End (E2E) also referred to as functional tests are tests to ensure that your entire application works as seen from the viewpoint of a user. The user does not know about how the internals work, that’s why this is sometimes called Black Box Testing.

When it comes to speaking how many tests there should be for each test type then you can assume that you will write mostly Unit Tests, a moderate amount of Integration Tests and a relatively small amount of E2E Tests.

Test cycles

image.png

Each test starts off by writing a failing test, then you write production code to make the test pass and finally you refactor the code. This is called red-green-refactor.

When you bring Integration and Unit Tests together you proceed like this: Start by writing a failing Integration Test, then move into the inner cycle of Unit Tests and do red-green-refactor until the outer cycle (the Integration Test) passes. At this time you stop development until you write another failing integration test.

Test tools

| Type of test tool | Description | |

Search articles

Type a word to search published articles.

Open the search page