Testing Pyramid : Introduction and Importance

Anand Ujjwal
4 min readJul 1, 2018

--

What is software testing ?

For me testing is about gaining confidence that your code does what you think your code should do. Properly tested code operates in a consistent and dependable manner which gains customer’s/user’s trust. A software system with no tests, or tests that aren’t thorough enough, will suffer from outages and regressions that disappoint users.

The Testing Pyramid

The Testing pyramid is a way of thinking about different kinds of automated tests should be used to create a balanced portfolio. This concept was developed by Mike Cohn at a time when most software testing was done using manual manipulation of the software’s interface.

Testing Pyramid

End To End Tests / UI Tests

Tests that test the system just like a real live end user would. They mimic the user’s interactions in the form or a script. It tests both the client’s side logic as well as the backend system, to verify that the client is able to communicate with the backend system and that state is updated and persisted properly between the client and the backend. It’s a beautiful, simple test, that tests the complete system end-to-end.

Cons of UI tests:

  • UI tests are very slow
  • They are very fragile

They are always very fragile. Changing the user interface often breaks the corresponding UI tests. So we have to be careful about how we write these things, and try really hard not to make them overly fragile.So because of their speed and fragility, we tend to use UI tests more sparingly, and save them end-to-end style smoke tests.

Integration Tests

It verifies the external behaviour of a single service and giving some level of confidence that things are properly hooked up.Integration tests mimics the HTTP calls the browser would normally be making on behalf of the user as they were logging .
They don’t go through the UI, therefore they are no where near as slow or fragile.

Cons of Integration tests:

  • They are good at telling us when we have a problem, unfortunately they can’t really tell us precisely where .

For low level precision, that tell us exactly where things went wrong, we rely on the unit test.

Unit Tests

Tests that verify the behaviour of class methods or functions inside a service. These tests take a code file from the service’s codebase, and execute its functions or class methods using different inputs, while verifying the output of the functions for each input.

Pros of Unit tests :

  • In enables them to make changes, without fear of breaking everything.
  • Unit tests are the fastest, most productive form of automated test we’ve got.
  • can pinpoint exactly where something fails when a test breaks.
  • Are inexpensive.

Cons of Unit tests:

  • unit tests do periodically miss bugs that can sometimes occur only when you hook things up.

Which is why integration and UI tests are still valuable.

How do we know which ones to write , Unit Tests or End to End Tests ?

If you give me an application in a set of really well unit tested modules put together , I must say that I have very less confidence that it will run end to end with all units fit perfectly.

End To End Testing gives us the confidence to answer some of the questions like ..

How my user will see this?
Does my front end communicate with my backend ?
Did all units fit in place perfectly?
Am I ready to release this code ?

End to End Testing is not a replacement to unit testing but its a really nice complement to it.

Conclusion

In order for tests to be effective they must be more than just a sidebar in the development process. Tests must be an integral part of the development and release pipeline and tests must be empowered to stop the release of failing code.

  • Code that fails tests should never be merged into your code repository.
  • Code that fails tests should never be released.

Follow the norms of testing pyramid and always be proud of what code you release.

If you liked this post, please share, comment and give few 👏 😊

--

--