Mocked dependencies

Seldom, some tested classes are so simple as our calculator class and most of the times they will have dependencies which in turn also have dependencies. So, unit testing becomes a bit more complicated. In fact, the ease with which unit tests are written has become a litmus test for the quality of the code being tested--the less complicated the unit test, the better the code.

As our second example of writing unit tests, let's go into the "real world" and test one of the classes we wrote in this book, namely the UserTypesAccess class. If you remember from Chapter 10, Access control, we created this service to be used on routes as an access checker. Although we can write functional tests that verify that it works well as ...

Get Drupal 8 Module Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.