lundi 9 juillet 2018

Angular 5: A good way for unit tests, integration tests and e2e tests?

Hey there, for our small and new company I need to develop a testing concept on how we want to test our Angular 5 application. Since we all have not much experience on testing, I'm not exactly sure on how to begin with. Where to draw the line between isolated unit tests, shallow unit tests, integration tests and e2e tests.
We have a core-folder with all the services (http, authentication, storage, translation ...) and some guards. For this I would use isolated Unit tests. Then we have an (core-)UI-folder with all the needed components to create an UI (e.g a tree, forms, grids, navigation, charts ...) And last we have a module-folder (e.g. useradminitration, customers) with modules (with routes) that contain components like profile, edit, add. These components are using the UI-components (which are using the core-services).

My approach would be:

  • isolated unit tests for the core-services and pipes (testing every function)
  • shallow unit tests for the UI-components. Mocking every dependency, testing Inputs, Outputs, Change Detection, template testing (what about the components children?)
  • Integration tests for the module-components. Not exactly sure how to do this. Since integration tests test the "whole application" (or a whole module like useradminitration) I would write a spec for each module and configure every component there.
  • E2E Tests for the module-folder

For example:

Isolated Unit Test for query.service.ts

  • mock every other dependency with fake data
  • test every function

Shallow Unit Test for the form.component.ts (uses the query.service and other services)

  • mock the services

  • create the TestBed component

  • test Inputs, Outputs, CD, functions

  • template testing (what exactly?). Since the form.components template uses other components like form-element (to display the correct input-type, like checkbox, textfield, radios...) the shallow unit test wouldn't render the form-element.components right?

Integration Test for useradministration (useradministration.module.ts: profile.component.ts, edit.component.ts, add.component.ts)

  • These components are using the form.component in their template and some other injected services (activatedRoute for example) So do I only need to mock the activatedRoute?

  • Import useradminitration.module in the TestBed

  • Create all components (profile, edit, add)

  • Test the components (would it be better to test the form.components Input/Ouput/CD here instead of testing it in the shallow unit test for the form.component?)

E2E Tests for each component in the module-folder

Is this a good way to test our application? I'd really appreciate some adives on how to handle this. Thank you!

All the best

Aucun commentaire:

Enregistrer un commentaire