ohif-viewer/platform/docs/docs/development/testing.md
Alireza 7f0ad6f84d
feat(cli): Ohif cli for modes and extensions modification (#2696)
* feat: Add initial cli tool structure

* feat: add copying template files

* feat: Add mode template and command

* feat: Add readme template generation

* feat: Add documentation to extension template

* feat: Enhance documentation of the template mode

* fix: cli module type

* feat: Add config-based mode and extension registration (#2660)

* feat: Add ohif cli add/remove extension/mode (#2661)

* Basic working CLI for add-extension and remove-extension

* Basic cli for add/remove extension/mode, lots more to do.

* Cleanup and harden]

* feat: Add list of tasks to add-mode

Co-authored-by: Alireza <ar.sedghi@gmail.com>

* feat: Add git initialization for the mode or extension template (#2662)

* fix: package json file to include templates

* feat: Add git initialization for the mode or extension template

* feat: Add more checks of git and target dir

* feat: refactore library utilities

* feat: Add the list command to print extensions and modes (#2664)

* feat: Add the list command to print extensions and modes

* Add todo

* Feat/ohif cli validation + auto install (#2671)

* WIP

* Working mode keyword verification

* Validation

* auto install extensions based on modes

* WIP remove unused extensions on removeMove

* Working add-mode, remove-mode automatic extension management.

* If extension is in used by a mode, don't allow the CLI to uninstall it

* Cleanup addExtension

* cleanup removeExtension and addMode

* Cleanup removeMode

* Update existing extensions with the needed keywords/peer deps

* Fix broken config

* Feat/cli search (#2677)

* feat: refactor pretty print for console

* feat: add search for modes and extensions

* fix: ugly colors

* Feat/ohif cli error handling publishing (#2679)

* WIP

* fix: webpack imports

* wip

* fix: react router dom private routes

* from last commit

* wip

* fix: webpack prod builds

* WIP

* Working regsitration with new IDs

* Stable

Co-authored-by: Alireza <ar.sedghi@gmail.com>

* verify extensions when constructing modes. (#2681)

* verify extensions when constructing modes.

* Add version to unit tests so it conforms to schema

* Update ohif utils exposed via @ohif/core

* Fix import

* fix tests

* feat: ohif-cli link local modes/extensions for development (#2682)

* feat: enable cli to work with project root

* feat: add initial link package

* feat: add link and unlink extension

* feat: add link and unlink mode

* erro handling for link-package

* feat: add comment on ohif-cli linking for development (#2686)

* Docs/ohif cli (#2687)

* feat: Add documentation for templates

* feat: Add more documentation

* Fix/core publish (#2685)

* versions

* wip

* remove webpack clean output

* fix publish

* use next as dist tag for v3 for now

* fix webpack pro recipe for output

* fix: lerna publish next

* fix(cli): fix issues when trying to link an extension or a mode (#2725)

The generated package.json doesn't contain keywords property which is
required by the linkPackage function. The module apth wasn't correclty
handled too, and when there is no pluginOptions, it fails while reading
the file or while generating a default configuration.

* make dicom pdf and video work after cli merge

* add axios dependency

* comment out the chdir for now

* create id and version based on user inputs

* customizable path for extension and modes

* fix template to make the template mode load

* fix the questions to loop if path is not desirable

* fix templates

* correct package json order

* unify the package creation for extension and mode

* bump versions for each package

* bump extension versions to 3.0

* add gitignore to templates

* fix version requirements when ^

* update docs

* update docs and fix tests

* try to fix the tests

* bump node version

* remove the version from extensions

* remove the version from modes

* remove version from extensionManager

* fix eslint

* revert husky version

* fix eslint

* fix node version for new eslint

* fix documentatoin removing version

* fix cicle ci image version

* fix circle ci node image

* fix circle ci node image

* add back the video and pdf

Co-authored-by: Matthis Duclos <matthis.duclos@gmail.com>
Co-authored-by: James A. Petts <jamesapetts@gmail.com>
2022-04-06 13:28:42 -04:00

8.4 KiB

sidebar_position sidebar_label
6 Testing

Running Tests for OHIF

We introduce here various test types that is available for OHIF, and how to run each test in order to make sure your contribution hasn't broken any existing functionalities. Idea and philosophy of each testing category is discussed in the second part of this page.

Unit test

To run the unit test:

yarn run test:unit:ci

Note: You should have already installed all the packages with yarn install.

Running unit test will generate a report at the end showing the successful and unsuccessful tests with detailed explanations.

End-to-end test

For running the OHIF e2e test you need to run the following steps:

  • Open a new terminal, and from the root of the OHIF mono repo, run the following command:

    yarn test:data
    

    This will download the required data to run the e2e tests (it might take a while). The test:data only needs to be run once and checks the data out. Read more about test data below.

  • Run the viewer with e2e config

    APP_CONFIG=config/e2e.js yarn start
    

    You should be able to see test studies in the study list

    OHIF-e2e-test-studies

  • Open a new terminal inside the OHIF project, and run the e2e cypress test

    yarn test:e2e
    

    You should be able to see the cypress window open

    e2e-cypress

    Run the tests by clicking on the Run #number integration tests .

    A new window will open, and you will see e2e tests being executed one after each other.

    e2e-cypress-final

    Test Data

    The testing data is stored in two OHIF repositories. The first contains the binary DICOM data, at viewer-testdata while the second module contains data in the DICOMweb format, installed as a submodule into OHIF in the testdata directory. This is retrieved via the command

    yarn test:data
    

    or the equivalent command git submodule update --init When adding new data, run:

    npm install -g dicomp10-to-dicomweb
    mkdicomweb -d dicomweb dcm
    

    to update the local dicomweb submodule in viewer-testdata. Then, commit that data and update the submodules used in OHIF and in the viewer-testdata parent modules.

    All data MUST be fully anonymized and allowed to be used for open access. Any attributions should be included in the DCM directory.

Testing Philosophy

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

You're an engineer. You know how to write code, and writing tests isn't all that different. But do you know why we write tests? Do you know when to write one, or what kind of test to write? How do you know if a test is a "good" test? This document's goal is to give you the tools you need to make those determinations.

Okay. So why do we write tests? To increase our... CONFIDENCE

  • If I do a large refactor, does everything still work?
  • If I changed some critical piece of code, is it safe to push to production?

Gaining the confidence we need to answer these questions after every change is costly. Good tests allow us to answer them without manual regression testing. What and how we choose to test to increase that confidence is nuanced.

Further Reading: 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. An expensive test is worth it if it gives us confidence that a payment is processed, but it may not be the best choice for asserting an element's border color.

Test Type Example Speed Cost
Static addNums(1, '2') called with string, expected int. 🚀 Instant 💸
Unit addNums(1, 2) returns expected result 3 ✈️ Fast 💸💸
Integration Clicking "Sign In", navigates to the dashboard (mocked network requests) 🏃 Okay 💸💸💸
End-to-end Clicking "Sign In", navigates to the dashboard (no mocks) 🐢 Slow 💸💸💸💸
  • 🚀 Speed: How quickly tests run
  • 💸 Cost: Time to write, and to debug when broken (more points of failure)

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 parameter types.

Example Tooling:

Unit Tests

The building blocks of our libraries and applications. For these, you'll often be testing a single function or method. Conceptually, this equates to:

Pure Function Test:

  • If I call sum(2, 2), I expect the output to be 4

Side Effect Test:

  • If I call resetViewport(viewport), I expect cornerstone.reset to be called with viewport

When to use

Anything that is exposed as public API should have unit tests.

When to avoid

You're actually testing implementation details. 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

We write integration tests to gain confidence that several units work together. Generally, we want to mock as little as possible for these tests. In practice, this means only mocking network requests.

End-to-End Tests

These are the most expensive tests to write and maintain. Largely because, when they fail, they have the largest number of potential points of failure. So why do we write them? Because they also buy us the most confidence.

When to use

Mission critical features and functionality, or to cover a large breadth of functionality until unit tests catch up. Unsure if we should have a test for feature X or scenario Y? Open an issue and let's discuss.

General

End-to-end Testing w/ Cypress