I've recently started writing unit tests for angular app I'm working on. There is one thing that I'm not sure about and that's a difference between unit test and integration test in context of Angular.
Assuming that I have a controller to test which depends on another (non angular) service, should I create a mock of a service or try to use real service when it's possible.
If I inject the service itself doesn't that mean I'm creating an integration test instead of a unit test?
I'm asking about that because my work colleagues keep writing tests that inject real servicesand still call them unit tests. It sucks big time especially when you have to debug errors from injected services in tests and each service depends on 5 other services...
The purpose of a unit test is to verify underlying unit's behavior in isolation from the environment and other units. Essentially, if your system under test, or the test itself, interacts with external systems, this is not a real unit test.
A couple of months ago I have written an article about this topic. Check it out for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With