dasch-swiss / dsp-ui-lib

Reusable Angular elements for Angular applications based on DSP-API and DSP-JS
https://dasch-swiss.github.io/dsp-ui-lib
GNU Affero General Public License v3.0
2 stars 4 forks source link

Define Best Practices for Unit Tests #3

Open tobiasschweizer opened 4 years ago

tobiasschweizer commented 4 years ago

AngularNYC - Angular Unit Testing Best Practices - Joe Eames (@josepheames) gives a good introduction to what can be considered best practices for unit testing. Note that in the video unit tests are referred to as tests of a component's class only whereas integration tests also include a component's template (DOM).

The Angular testing guide recommends to "test DOM interaction with unit testing techniques" (https://angular.io/guide/testing#why-not-defer-dom-integration-tests-to-end-to-end-e2e-testing). I think it is crucial to include the DOM in the tests because much of our components' complexity comes from interaction with user input and reacting to it. The Angular testing guide also states that "a component is more than just its class. A component interacts with the DOM and with other components. The class-only tests can tell you about class behavior. They cannot tell you if the component is going to render properly, respond to user input and gestures, or integrate with its parent and child components." (https://angular.io/guide/testing#component-dom-testing).

So I think it all comes to the question what is considered to be unit. I think the DOM should be part of a unit test (also referred to as a DOM integration test).

tobiasschweizer commented 4 years ago

difference between unit tests and e2e test: https://stackoverflow.com/questions/48064021/what-is-the-real-difference-between-ng-test-and-ng-e2e

tobiasschweizer commented 4 years ago

see https://medium.com/@kevinkreuzer/test-your-components-using-angular-materials-component-harnesses-f9c1deebdf5d: intro to Angular 9 Material Harness