# T Unit Tonik Testing

> Testing Conventions

- Skill: `tomevault-io/t-unit-tonik-testing` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/t-unit-tonik-testing`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/t-unit-tonik-testing/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/t-unit-tonik-testing

---


# Testing Conventions

## Matchers

- Always use `isTrue` and `isFalse` matchers instead of bare `true` and `false`.
- Never use `equals()`; test against the value directly.

## Code Generation Testing

- **PREFER object introspection** over string testing for generated code:
  - Test constructor/method existence: `combinedClass.constructors.firstWhere((c) => c.name == 'fromSimple')`.
  - Test parameter types: `parameter.type?.accept(emitter).toString()`.
  - Test method properties: `method.lambda`, `method.returns`.
  - Test field names: `combinedClass.fields.map((f) => f.name)`.

- **Only use `contains(collapseWhitespace(...))` when absolutely necessary** for testing specific generated code content.
- **NEVER use bare `contains()` without `collapseWhitespace()`** for generated code — formatting differences will cause flaky tests.
- Use `collapseWhitespace` from [test package](https://pub.dev/packages/test): `import 'package:test/test.dart';`.
- When testing generated code strings, format both expected and actual with `DartFormatter`.

## String Testing Guidelines

- When testing generated code strings:
  - **ALWAYS test full method/function bodies**, never fragments or individual lines.
  - Format both expected and actual with `DartFormatter` before comparing.
  - Compare using `collapseWhitespace(actual) == collapseWhitespace(expected)` for full body equality.
  - When a generator returns `List<Code>` (statements), wrap them in a `Method` to produce a complete formattable body, then test the full body.
  - When a generator returns an `Expression`, wrap it in a complete method context before comparing.
  - **NEVER use bare `contains()` for generated code** — always use full body comparison or `contains(collapseWhitespace(...))` on a formatted complete body.
  - **NEVER test code fragments** (e.g., checking if output "contains 'FormData()'" or "contains '.toJson()'"). Always assert on the complete expected output.

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/t-unit) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-11 -->

