zmk/docs/docs/development/tests.md
Joel Spadin e1a925ff83 refactor(test): Run tests with pytest
Replaced the run-test.sh script with a Python script that runs our unit
tests through pytest. Tests are now run in parallel to speed up running
the entire test suite, and it allows for integration with other tools
that support pytest, such as IDEs.

Also removed a dependency on remarshal, because it depends on an old
version of PyYAML that conflicts with other Python packages in our
Docker image. Replaced it with yq.
2023-01-26 13:12:25 -06:00

1.8 KiB

title sidebar_label
Tests Tests
  • Running tests requires native posix support.
  • Any folder under /app/tests containing native_posix_64.keymap will be selected when running west test.

Running Tests

All the following commands assume you have a terminal opened to the zmk/app directory.

First, make sure all Python dependencies are installed:

python3 -m pip install -r scripts/requirements.txt

Tests can then be run from Zephyr's west tool with the test subcommand:

west test

Running it with no arguments will run the entire test suite. You can run a single test case or test set by providing the relative path from zmk/app/tests to the test directory, e.g.

# Run all tests cases in the toggle-layer set
west test toggle-layer

# Run the toggle-layer/normal test case
west test toggle-layer/normal

Any additional arguments are passed through to PyTest.

Creating a New Test Set

  1. Copy the test set that most closely resembles the tests you will be creating.
  2. Rename the newly created test set to the behavior you're testing e.g, toggle-layer
  3. Modify behavior_keymap.dtsi to create a keymap using the behavior and related behaviors
  4. Modify test_case/native_posix_64.keymap for a simulated use case
  5. Modify test_case/events.patterns to collect relevant logs to the test
  6. Modify test_case/keycode_events.snapshot for to include the expected output
  7. Rename the test_case folder to describe the test.
  8. Repeat steps 4 to 7 for every test case