Code Add Tests

Table of Contents

When to use this skill

When you need to create or extend unit tests for an ORE Studio component. For investigating a failing test, use the sibling test-failure-investigator.

How to use this skill

The canonical reference for how an ORE Studio test looks is Unit test conventions — file layout, naming patterns, includes, test-case shape, tags, generators, database helpers. Read it first if you have not seen the contract.

  1. Identify component and layer — domain, repository, service, security, messaging, or generators. This sets the file name (<layer>_<class>_tests.cpp), the include set, and the default tag ([<layer>]).
  2. Pick the test categories you need:
    • Domain: basic construction, JSON serialisation, faker-generated data.
    • Repository: write single, write batch, read latest, read by field, temporal queries.
    • Messaging: serialize/deserialize roundtrip (empty + populated).
    • Generators: generator produces valid entity, batch generator produces N.
  3. Write each test case following the standard shape from Unit test conventions§"Test-case shape":
    • auto lg(make_logger(test_suite)); at the top.
    • Build the system under test (use a generator when available).
    • BOOST_LOG_SEV(lg, info) << sut; before assertions.
    • CHECK for non-fatal; REQUIRE for "rest of case is pointless if this fails".
  4. Pick the right database helper for repository tests (database_helper vs scoped_database_helper — see Unit test conventions§"Database helpers"). New components prefer scoped_database_helper (tenant-isolated, no truncation needed).
  5. Build and run the new tests via How do I build the system? and How do I run the tests? — confirm everything passes locally before pushing.
  6. Self-check against the reviewer checklist — the "Unit tests" section of Code review checklist is what reviewers will apply.

Recipes

Reference

Emacs 29.1 (Org mode 9.6.6)