In this lecture, we are going to move on to end to end testing.
It's one of the most challenging types of tests to write.
A lot can go wrong with end to end testing.
Let's get into why E to E testing is important.
The problems that come with it and the tool will be using for handling end to end testing.
First things first.
What is end to end testing?
End to end testing as a way to check if an application is behaving correctly by automating a browser
to mimic user behavior during the development lifecycle of our application, we could write code, switch
to the browser and test our code.
This process is known as manual testing.
Rather than performing these tasks manually, we can write a program to perform the same actions.
For example, we can click links, submit forms, scroll around, etc. Everything we can do in the browser,
it can be automated.
In theory, it seems like end to end tests can be the best approach to testing.
Unfortunately, end to end testing may not be the best way to test an application.
There are downsides to this type of testing.
Firstly, they can be slow to run.
A couple of things need to happen before the test is complete.
The program needs to turn on a server, compile your project, open the browser, navigate to the app,
perform your tests, capture actions and generate a report.
It's a series of steps that need to be taken for verifying tests.
You'll see how slow a test can run when we run our first test.
Secondly, E to E testing can be unreliable and end to end test runs the application as if it were fully
functional.
This means that any APIs we're using will need to work.
If a request takes too long, this can cause the test to fail.
Lastly, debugging a test can be difficult.
If an error occurs, you'll need to take the time to figure out why this process can be challenging
because unlike unit tests, we're loading the entire application.
The problem can be with any components, it can be with any third party module we installed.
It's challenging to track the root cause of an error.
This doesn't mean that you should never write end to end tests.
In fact, they're the most useful kind of tests you can write, mainly because they allow you to observe
the behavior of your application.
This perspective is something that unit or snapshot testing can't provide you.
Both types of tests are great for testing individual parts and pieces, but at the end of the day,
you will need to see if everything works together in unison.
Two components may work separately, but do they work together?
End to end testing can help answer.
That's another disadvantage of unit testing and snapshot testing is that they can't help you test navigating
between pages.
You can't test how layouts will react whenever the state or route changes.
And to end testing doesn't have these limitations.
There's one last question to answer before looking at some code.
What should we be testing?
You should have as few ends to end tests as possible.
You will want to test the main actions that will be performed on your app.
For example, authentication is a typical action that users may perform.
If you're building an E commerce shop, you may want to write a test for purchasing a product.
You shouldn't test small actions, like navigating from one page to the next.
Now that we have a basic understanding of end to end testing, let's talk about tools and the angular
community.
Without a doubt, Cypress is considered the most popular tool for performing E to E testing.
More than half of developers use this tool by default.
This tool is not integrated into Angular.
Luckily, installing Cypress with a project is easy.
In the resource section of this lecture, I provide a link to Cypress for this course we'll be using
Cypress.
It's fast and well documented.
Another choice for testing is Protractor.
Protractor was considered the official solution for testing.
However, it's no longer recommended.
From time to time you may hear about this tool.
Just know that the Angular team is moving away from this tool.
The team recommends Cypress for all your testing needs.
Let's head back to the Cypress site.
On the menu.
There's a page called pricing.
Click on it.
First and foremost, Cypress is entirely free and open source.
There aren't any limitations to using Cypress.
The development team behind Cypress has developed an additional service called Cypress Dashboard.
Their service allows you to run tests on their servers instead of on your own machine.
It can even run tests in parallel ization, which is running multiple tests at the same time.
This feature will produce faster results.
It does cost money.
Still, it is an excellent service.
If you're working on a team, you don't have to use this service.
Cypress can run on your machine with minimal setup.
We'll be running Cypress on our machines in your editor.
Open the command line.
Cypress can be installed by running the following command n g ad at Cyprus slash schematic.
We're using the angular cli to help us install this package.
The Cypress team maintains a package for integrating Cypress with an angular project.
This package will install Cypress, create the necessary files and update the package file with new
commands for running Cypress.
During this process, you may be asked to add a new command.
Select.
Yes.
Once the package has been installed, we can start using Cyprus in the next lecture.
Let's take time to explore this tool's features.