Skip to content

Latest commit

 

History

History
110 lines (78 loc) · 4.07 KB

testing.md

File metadata and controls

110 lines (78 loc) · 4.07 KB

Testing

Run tools/test to run all our test suites. This command is typically quite fast (5-10s, sometimes less), because it only rechecks tests related to the files you've changed.

You can run all our tests with tools/test --full.

To see all options, run tools/test --help.

Unit tests: JS

tools/test jest runs the unit test suite.

Our tests are written using Jest.

To write a test, place a Javascript file with the -test.js suffix in the __tests__ directory inside of any subfolder of /src. The test will be automatically picked up by the test runner.

Use deepFreeze to test functions which access redux state. This won't allow the object to be mutated and hence will eventually fail tests in case of mutation.

Unit tests: Android

We have a small, nascent suite of unit tests for our Android-native (Kotlin and Java) code.

tools/test android runs this suite, as well as building all the Android code.

Tests are written in Kotlin, using JUnit 4 and the Truth library. If you're writing Android unit tests:

  • Definitely read the short Android guide on principles of testing -- it's a good writeup.
  • Definitely also read the short Android guide on local unit tests, which has more concrete details about the APIs we use here.
    • (A "local unit test" is Android jargon for a genuine, self-contained unit test, specifically a test that doesn't require an Android device to run on. All our unit tests are "local unit tests".)

Other sources which might be helpful to read or refer to:

Functional tests

Functional tests have not been set up. We plan to use Appium.

Linting

We use ESLint to catch many kinds of style issues, together with Prettier to maintain consistent formatting.

Our lint config starts from the Airbnb guides (for ES6 and for React), with a number of specific changes.

Prettier is an "opinionated" tool, which is a euphemism for having virtually no configuration options; and unfortunately a few of its unchangeable "opinions" are outright harmful. So we use prettier-eslint to overrule it on those points; the details are in a small, formatting-only ESLint config file.

For proper results, always run ESLint or Prettier through our canonical interfaces:

  • tools/test (or tools/test lint prettier for these steps alone);
  • tools/test --fix, to actually modify the files to fix issues where possible; or
  • in your editor, with our recommended editor config.

If you find another interface more convenient, please send a PR and/or mention it in chat! We'll be interested to learn about it, and to see what we can do to support it.

Type checking with Flow

We use Flow and flow-typed to find and prevent type related issues.