Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular unit test vs integration test

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...

like image 818
Łukasz Avatar asked Mar 13 '23 11:03

Łukasz


1 Answers

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.

like image 110
Sergey Kolodiy Avatar answered Mar 20 '23 05:03

Sergey Kolodiy