Search code examples
angularunit-testingjasmineintegration-testingkarma-jasmine

Angular what can be tested in the integration test and what in the unit test


Generating a component via Angular CLI creates a .spec file. Should integration and individual tests be included there? How can I tell if a test is individual or not.

For example, I am testing a method that emits a value through Output, subscribing to EventEmmiter and checking the value during a subscription, is it a unit test?

The second example. I'm testing the tooltip display method, which is a bootstrap component, so this is an integration test, because you need interaction with another component?

The third example, I am testing a method that changes variables in the component and finally redirects to the router.navigate, check if the router has redirected to the given address - is it an integration test?

I can not find a single answer in the documentation.


Solution

  • Generating a component via Angular CLI creates a .spec file. Should integration and individual tests be included there?

    Note that the spec file is actually optional. But in any case, you typically wouldn't want your integration tests combined with your unit tests no matter how you define the seams in your application. That's because they typically run for different reasons, at different times, in different environments. That being said, the only difference between them might be injecting a mock verses using a concrete implementation.

    How can I tell if a test is individual or not.

    This, and the rest of your questions, depend on where you fall on the testing-purist spectrum and how you relate that to your development reality. For example, Roy Osherove defines a "unit" as:

    [a] "unit of work" or a "use case" inside the system.

    That implies some amount of integration for any reasonably designed, non-trivial application. One thing's for sure though: if your test relies on a db connection, network availability, API/Service, file system, or any other volatile dependency, it's definitely an integration test.