The different types of Angular tests (and when to use them)


Hey-yo, Angular friends!

Today I'm going to teach you about the 6 different test types for Angular applications.

I'll use a dash of humor to tell you about the advantages - as well as the disadvantages - of every type of Angular test.

And also, which types of tests are better for your scenario.

Oh... And we'll even be talking about my nosy neighbors, Angular love stories, and...

angular-test-types

Oops!

...

Um...

Err...

I got a bit distracted.

giphy

Anyways, here's the 6 different Angular test types.

1. Unit Tests

First up, we have unit tests. These tests are like your nosy neighbor who knows everything about you, because they get super close to the nitty-gritty details of your code.

They scrutinize individual methods and functions of the classes, components or modules used by your software.

But hey, they're cheap to automate and can be run faster than you can say "continuous integration server."

If you're doing TDD, then unit tests definitely the way to go about TDD-ing your Angular application.

Unit tests also tend to be more robust and less brittle then smoke and E2E tests.

2. Integration Tests

Next, we have integration tests.

These integration tests are like a first date, because you're testing if different modules or services used by your application can work together. Will there be chemistry or will it be a total flop?

These tests can be a bit pricey because they require multiple parts of the application to be up and running, but hey, love (and testing) can be expensive.

They also tend to require more maintenance, especially if you're doing a lot of refactoring.

3. Functional Tests

Functional tests are like your personal trainer. They only care about the output of your actions and don't give a hoot about the intermediate states of your system. They're all about making sure your application meets the business requirements. So if your app is slacking off, these tests will whip it back into shape.

4. E2E tests

Now, here's where things can get a bit confusing.

End-to-end tests are like a marathon - they're long and can test your endurance. They replicate a user's behavior with the software in a complete application environment. It's not just about loading a web page or logging in - we're talking about complex scenarios like verifying email notifications and online payments.

These tests are super useful, but they can be expensive and hard to maintain when they're automated. So be sure to stretch before you run these tests.

These are the longest to write and run. They are the most fragile. And they're the hardest to debug.

That's why I do not recommend that you use only E2E tests. Instead, create E2E tests for about 6 most-common user paths through your Angular app. And then use integration or unit tests for more robust testing.

5. Acceptance Tests

Acceptance testing is like a job interview. You need to prove that your system satisfies its business requirements and can perform well under pressure. These tests require the entire application to be up and running, and focus on replicating user behaviors. But they can also measure the performance of the system and reject changes if certain goals aren't met. So dress to impress and bring your A-game.

6. Smoke Tests

The name smoke test is said to have come from way back when you had to test a circuit board after soldering it together.

motherboard

You would turn it on and if there was no smoke, then your job was done. But if there was smoke, you had done something wrong.

However, this metaphor actually goes back a lot further to plumbing.

Plumbers sometimes use smoke tests to check for leakage in the pipes that they just put together. By forcing smoke through the beginning of the pipe, they can find leaks.

And that's what smoke tests are. You start at the beginning of a user journey (e.g. beginning of pipe) and you have an end goal in mind (e.g. end of user journey). And your smoke test looks for any leaks inside of this user journey.

These are really the same type of test as an E2E test. And again, don't bet your bread and butter on these types of tests.

Instead, use them sparingly to test the most common use-case scenarios for your application.

Conclusion

Today, you've learned about the 6 different Angular test types.

If you have any questions or comments don't hesitate to reach out.

Till later,

signature

Further Reading