(Angular) What should I test? Here's how you can get the best ROI 💰💰💰
Published on 13. Apr. 2021
- Angular Testing
What type of Angular tests will give you the highest ROI?
Here's your 3 minute guide to help you decide what parts of your Angular project you should be testing.
Do you ever feel lost when trying to write good Angular tests?
Say, any developer attempting to write their first tests for an Angular app might rather grab a drumstick and herd a mob of hairy cats down the street instead.
It's easy to get lost trying to decide which pieces of the Angular application to test.
Err... what parts must I test and what can I skip?
Do we need 100% code coverage?
And should I be writing tests for that front-end UI stuff that's always evolving? UI tests tend to be brittle so where should an Angular developer set their bug traps?
Most importantly, how do I make sure that I get the best ROI for my time?
That my friend, is a great question. If you want a quick answer then go ahead and skip to the bottom of this article in the summary section. Otherwise, we'll peal the covers back a bit and look at the main pieces of an Angular application and the priorities they deserve.
Components are... well... components.
They are the most basic UI building block in an Angular app and their only function should be to display data.
A component should have no concern as to business logic or where the data came from. It should only focus on taking the data it's meant to receive and presenting it to the user in a meaningful way.
In general, it's a waste of time to test these heavily. Especially as they're prone to lots of evolving as your Angular app grows and expands.
To focus lots of developer energy on making sure your components are completely tested is usually a poor investment choice.
Here's where you'll take an aim and make a great shot!
Assuming that your Angular app has followed general best practices...
...and uses services to handle business logic, data access, http calls, and all the other spicy background stuff...
...then this is where anyone writing tests oughta be licking their lips.
Make sure your Angular services are tested well. By focusing on this you'll have a greater guarantee of better ROI.
Not sure how to get started? The Angular website has a great guide to get you started.
Definitely put those custom pipes to the fire. Once again, these play an important role in business logic. Making sure they're working properly is a great way to get a better ROI when writing tests.
So what should you test?
Write bug traps for every piece of the application that contains business logic. This would be pieces like...
- Custom pipes
- Helper functions
- Stage Management
By focusing on the pieces with the business logic and making sure it's tested well you'll be cutting to the heart of the matter and writing Angular tests for the pieces that matter.
And one final tip...
You should aim for 60 to 80 percent code coverage when writing tests for your Angular application. And rivet your eye on making sure the business logic in the application is well tested.
Questions or comments? Don't hesitate to reach out to me.