[MUSIC]
In the previous lecture and exercise that followed the lecture,
we have examined the use of unit tests in Angular.
We have seen how the different parts of our Angular application, the components,
the services, the directives, the pipes can all be tested using unit tests.
But of course,
unit tests do not reveal everything about the interaction among the components.
That is where the end-to-end testing strategies enable us to
see the entire application working as a single unit.
So in this lecture, we will examine the use of End-to-End tests and
what role they play in the overall testing strategy for our Angular applications.
In the exercise that follows, we'll look briefly at how we can conduct end-to-end
testing for our Angular application, using a tool called Protractor.
As we have already learned in the previous lecture, unit tests
provide us with a wonderful opportunity for testing our units in isolation.
Making sure that our units perform what they're expected to perform,
their logic is correct, and interaction between the component and
its template are well-established.
But of course, unit tests do not
complete the entire picture of how a typical Angular application works.
You do not have individual units working in isolation.
Instead, your components interact with services.
The components may make use of types.
The services, in turn, will interact with the backend to fetch the data.
And then the component themselves will be responsible for
rendering the views using the templates for the component.
So how does this whole set of units work together?
And how do we ensure that the working together of this
units are completely free of problems?
So that is where end-to-end testing and along the way,
integration testing helps us to cover these kind of scenarios.
Of course, unit tests play an important role in the overall testing strategy.
But without doing end-to-end tests,
we can't be completely sure that our application is performing as expected.
One thing that I must emphasize is that unit tests are fast and
very easy to repeat and can be done multiple times.
Integration tests and end-to-end test are slow, and so they are used
only sparingly for confirming that your application is performing as expected.
So when we look at our overall testing strategy,
we can look at it as being organized in the form of a pyramid.
At the bottom of the pyramid, occupying the entire base and
forming the foundation of our overall testing strategy, are unit tests.
As we have learned, unit tests allow us to test the individual units in isolation,
making sure that their logic and
the way these units work is correct.
And these tests can be repeated very frequently.
And indeed, should be repeated frequently to ensure that the individual units
are performing as expected.
Of course, at a second level of this strategy would be integration tests.
How a small group of units work together in
implementing whatever is necessary to be done by those group of units?
So perhaps we might test a component together with
its services to see how the flow of information between them happens.
But at the top of this pyramid is end to end tests where
we look at the overall application.
And how well the overall application is performing and
meeting its expected requirements.
So that is where we see the use of end-to-end tests.
As you might already expect by this diagram, end-to-end tests are slow.
And so we don't carry out end-to-end tests very frequently, instead,
unit test form the core strategy for our testing of our Angular application.
End-to-end tests do contribute in the overall picture, but they are done not so
frequently, but still are an essential part of our testing strategy.
So how do we carry out end to end tests?
Let's briefly talk about the tools that are available for us.
The Angular testing environment for
end-to-end tests is supported by a tool named Protractor.
Who says that geeks don't have a sense of humor?
Protractor, Angular, there you go.
So what is exactly is Protractor?
Protractor is, as you might expect, a node program.
So this enables us to carry out end-to-end tests.
So Protractor runs the tests against your application.
So Protractor loads your application into a browser and interacts with
the application just like a real user will interact with your application.
So we are looking at interacting with your application,
although programmatically, but performing the kind of operations that
a typical user will perform like clicking on links, filling out forms.
Submitting forms, navigating to different parts of your application and so on.
So this is where Protractor leverages the use of a WebDriver to control
browsers on which the testing can be carried out.
One such app framework is called as the Selenium Framework,
which is used for doing automated testing within browsers.
If you are using Chrome as part of your testing strategy or Firefox,
then you can use what is called a direct connect.
That is available through a Protractor to directly connect to these browsers and
carry out testing within those browsers.
Now, the tests themselves leverage the adjustment framework for
expressing the test.
So you would still see the user describe an int and
before each that you have seen with unit tests.
Except that now, we are going to be leveraging the protractor support for
being able to generate real user-like interactions with our
application using code.
So that is what is we will learn in the exercise that follows this particular
lecture.
We will make use of Protractor and write our end-to-end testing strategies.
And of course, leverage the Angular CLI support for
carrying out end-to-end tests in the exercise that follows this lecture.
[MUSIC]