Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Should I Write Unit Tests if I have UI Automation Tests [closed]

If I have UI automation tests, why do I need to write unit tests?

If I need to check that a method returns some output for a given input, for example a result of an addition which is then displayed in a view, why do I need unit test if I can confirm that output in the view is correct (or not correct) through UI automation test

like image 398
pixel Avatar asked Dec 01 '22 10:12

pixel


1 Answers

Unit test and end to end test (UI tests) have two different purposes

  • Unit test tell you when unit of code (module, class, function, interface) has an issue

  • End to end tests tell you how that failure affects end to end output.

Lets use an analogy to understand why we need both.

Suppose you were manufacturing a car by assembling different components like carburettor, gear box, tyres, crankshaft etc. All these parts are being made by different vendors(think developers).

When car fails to work as expected, will you need to test individual components to figure out where the problem originates from ?

Will testing components before assembling the car, make you save time and effort ?

Typically what you want to do is to make sure each component work as expected (unit tests) before you add them to your car.

When the car does not work as expected, you test each component to find the root cause of the problem.

This typically works by creating an assembly line (CI pipeline). Your testing strategy looks like

  1. test individual components

  2. test if they work when interfaced with other components

  3. test the car once all components are assembled together.

This testing strategy is what we call a testing pyramid in programming.

Reading this might give you more insight : https://martinfowler.com/bliki/TestPyramid.html

like image 170
Nishant Avatar answered Dec 09 '22 18:12

Nishant