Guide for writing, running, and debugging unit tests for Cadence smart contracts using the built-in Cadence Testing Framework and flow test. Covers test file structure (_test.cdc, setup/beforeEach/tearDown), assertions and matchers, blockchain emulation (accounts, deployments, events, time manipulation), coverage reports, CI integration, and testing patterns. TRIGGER when: writing Cadence unit tests, debugging failing tests, using Test.assert / Test.expect / Test.assertEqual / Test.expectFailure, matchers (Test.equal, Test.beGreaterThan, etc.), Test.createAccount / Test.deployContract / Test.executeTransaction / Test.executeScript in tests, Test.moveTime, Test.eventsOfType in tests, Test.reset, flow test, flow test --cover, coverage reports, _test.cdc, "how do I test this contract", "test is flaky", "mock a capability in a test". DO NOT TRIGGER when: writing contract or transaction code itself (use cadence-lang), generating new contracts/transactions from scratch (use cadence-scaffold), auditing non-test code for security (use cadence-audit), running flow CLI commands other than flow test (use flow-cli), setting up flow.json contract aliases outside a testing context (use flow-project-setup).
$npx -y skills add onflow/flow-ai-tools --skill cadence-testingInstalls into the current project.
Run `npx skills use "https://github.com/onflow/flow-ai-tools" --skill "onflow/flow-ai-tools/cadence-testing"` and follow the generated skill instructions now. Read its complete output, redirecting it to a temporary file first if necessary. Resolve relative paths from the supporting-files directory it provides.
Use the skills in "https://github.com/onflow/flow-ai-tools" that are relevant to the current task. Run `npx skills add "https://github.com/onflow/flow-ai-tools"` and select the relevant skills, then follow their instructions.