How deep integration tests should be?

In my previous article I’ve pointed out the difference between tests for Angular components. During my research I’ve discovered a couple of interesting posts from Martin Fowler and Google Testing blog. See the links below.

As you may already know integration tests ensure that different units of the application are communicating with each other correctly. So you can imagine that one integration test may go through the whole application, testing more and more units working together in a perfect flow.

unit tests said it’s working

But do we really want it? Think about software as a chain of events. Software would be good and robust when all the chains are good and robust, but it’s too hard to examine the whole chain at once. That’s why we split it and examine first every link (with unit tests) and later examine closest links connections (with integration tests).

How might it be applied to Angular? First do shallow tests for each Angular component and later add integration tests to examine component interaction with its first-level children. Let’s take a look at the following components structure.

The dropzone template looks:

Unit test configuration for dropzone component would be:

So to achieve shallow unit test template you only declare tested component inside of the TestBed and nothing else. This means that all the elements in the template will be treated as simple DOM nodes, and only common directives (e.g., ngIf and ngFor) will be applied.

Integration test configuration:

In unit tests all the possible component scenarios are examined:

correct classes are applied to elements

correct values are put into HTML nodes

correct events are triggered on mouse events and etc.

in integration tests the points of integration are tested

correct output events chain

correct input values chain

Don’t forget about the wisdom from Google and 70/20/10 rule. And remember that integration tests only examine the flow and don’t try to test functionality which should be done by good old unit tests.

click on me!

Happy testing to you, my coding friends! And here are the articles for you from the smart guys.