Chapter 2
- Writing code test-first using the Test Drive Development (TDD) approach
helps us design classes and their interfaces. Tests serve as yet another client
invoking our code and as such helps us design flexible, loosely coupled
classes and interfaces. - Last but not least existing tests can serve as documentation. We can always
open a test to see how a given method should be invoked, what is a set of
accepted arguments. What's more, this documentation is executable and
always up to date.
Unit tests are of great help but they can't catch all the possible problems. In
particular all the configuration and integration issues won't be detected by
unit tests. To thoroughly cover our applications with automated tests we need
to execute higher-level, end-to-end (integration) tests as well. The goal of
integration tests is to exercise an assembled application and make sure that
all the individual units play nicely together to form a fully functional application.
Writing and maintaining automated tests is a skill apart that as any other skill needs
to be learned and honed. At the beginning of your testing journey you might feel
like testing practices are slowing you down and are not worth it. But as you get
more proficient with testing techniques you will appreciate how much time we can
actually gain by rigorously testing the code.
There is a quote saying that writing code without a version control
system (VCS) is like skydiving without a parachute. Today one
would hardly consider running a project without using a VCS.
Same applies to the automated testing and we could say: "Writing
software without an automated test suite is like climbing without a
rope or skydiving without a parachute". You can try but the results
will be almost for sure disastrous.
AngularJS team fully recognizes the importance of the automated testing and strictly
applies testing practices while working on the framework. What is fantastic, though,
is that AngularJS comes with a set of tools, libraries and recommendations that make
our application easy to test.
Unit tests
AngularJS adopted Jasmine as its testing framework: unit tests for the framework
itself are written using Jasmine and all the examples in the documentation are using
Jasmine syntax as well. Moreover AngularJS extended the original Jasmine library
with few useful add-ons that make testing even easier.