crtxdmp.

A collection of ideas, snippets and other things.


About testing

Try to isolate complex tasks and bugs in a unit test. It’s easier to develop against tests than the browser and it saves time.
Cut your business code in small testable units to get rid of using your browser while writing business logic at all.
It’s easier to prove that an error is gone if you prove that there is one beforehand with a failing unit test.
Functional/End2End tests are great, but they don’t help writing business logic.

Strive for a fully test driven development approach.

Most of you already heard about tdd, nowadays, it´s pretty common to use it.

If you are not familiar with it the three laws of tdd gives you a good head start.

  1. You must write a failing test before you write any production code.
  2. You must not write more of a test than is sufficient to fail, or fail to compile.
  3. You must not write more production code than is sufficient to make the currently failing test pass.

Test types

Unit test

A unit test is the smallest test we have. With it, we solely test a method and show that our low level code is working properly.

This type should be applied to the most things in our business logic and also common services are a good candidate for unit tests.
Applying such low level tests to other contexts like glue code can cause a lot of mess, make sure you only test code written by yourself and not the framework or external bundles.

Have in mind that those tests only check low level code. They are important but the composition of all parts needs be checked with integration tests, if not we will have an application which will work like this.

everything works but nothing as it should

Integration test

With integration tests we make sure that all our components work together nicely.
E.g. for our REST API we directly call the API via a web call and check the results.

End-to-end test

End-to-end tests utilize the frontend of our application to run the checks.
It mimics user behaviour to make sure the tested parts are working as expected from one end to the other.

Those tests are very expensive in terms of runtime but deliver the most value.

, — Aug 25, 2021