10 Testing your application

 

This chapter covers

  • The value of testing your Angular applications
  • How to set up and create unit tests to test individual pieces
  • Unit test strategies for directives, services, components, and pipes
  • How to implement e2e tests to test the application as a whole
  • Additional testing strategies

All the applications we’ve built could benefit from testing. Some developers dread writing tests, whereas others are probably wondering why I didn’t cover testing from the start. I consider testing essential, though it requires a set of new concepts and tools, which is why I waited till now.

Angular was designed to be highly testable, and projects created using the Angular CLI automatically set up basic testing scaffolding and tools for us to use. We’ll use the CLI provided tools and configuration in this chapter. Developers with experience using other tools can choose to set up something else on their own and use the ideas and concepts from this chapter with those tools.

10.1 Testing tools and setting up the chapter example

10.1.1 Testing tools

10.2 Unit testing

10.2.1 Anatomy of unit tests

10.2.2 Testing pipes

10.2.3 Testing services, stubs, and mocking HTTP requests

10.2.4 Testing components and using testing modules

10.2.5 Testing directives

10.3 e2e testing

10.4 Additional testing strategies

10.4.1 How much testing is enough?

10.4.2 When do I write tests?

10.4.3 What do I write, e2e or unit tests?

10.4.4 What if I don’t have time to write tests?

10.4.5 What about other types of testing?

Summary