ohif-viewer/docs/latest/contributing/testing.md
2019-08-21 17:42:33 -04:00

3.4 KiB

Contributing: Tests

Testing is an opinionated topic. Here is a rough overview of our testing philosiphy. See something you want to discuss or think should be changed? Open a PR and let's discuss.

Why do we write tests?

  • Increase confidance

Kinds of Tests

Test's buy us confidence, but not all tests are created equal. Each kind of test has a different cost to write and maintain. More costly tests

Test Type Example Speed Cost
Static addNumbers(1, '2') was called with a string, int was expected. 🚀 Instant 💸
Unit addNumbers(1, 2) returns expected result 3 ✈️ Fast 💸💸
Integration 🏃 Okay 💸💸💸
End-to-end When I click "Sign In", the page navigates to the dashboard. 🐢 Slow 💸💸💸💸

Static Code Analysis

Modern tooling gives us this "for free". It can catch invalid regular expressions, unused variables, and guarantee we're calling methods/functions with the expected paramater types.

Example Tooling:

Static code analysis can't test business logic.

Unit Tests

...

What should be unit tested?

Follow the top level exports. Anything that is exposed as public API should have unit tests. These are th

What should NOT be unit tested?

You're testing implementation details if:

  • Your test does something that the consumer of your code would never do.
    • IE. Using a private function
  • A refactor can break your tests

Integration Tests

...

End-to-End Tests

...

Further Reading