move-unit-testing

Write Sui Move unit tests with correct assertions and expected_failure handling.

10|5|Updated Mar 13, 2026
One-click install
npx skills add https://github.com/MystenLabs/skills --skill move-unit-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: move-unit-testing
Source: https://github.com/MystenLabs/skills/tree/main/move-unit-testing
Command: npx skills add https://github.com/MystenLabs/skills --skill move-unit-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Move unit tests for Sui commonly end up with incorrect conventions that cause brittle failures, missing diagnostics, or misleading expected-failure behavior.

Core Features & Use Cases

  • Test conventions for Sui Move: enforces correct patterns for naming test functions, using the right assertion style, and structuring test attributes.
  • Accurate expected-failure handling: ensures #[test, expected_failure(...)] is written correctly (including location when aborts occur in another module) and avoids dead-code cleanup after expected aborts.
  • Right test harness selection: guides when to use tx_context::dummy() versus test_scenario (multi-transaction, shared objects, init testing).

Use this when you are asked to add unit tests for a Move module (including success paths, abort/expected_failure cases, authorization checks, and shared-object scenarios) so the resulting tests match Sui’s best practices and are reliable under CI.

Quick Start

Ask the agent to write Sui Move unit tests for my module that follow Sui testing best practices, including expected_failure cases and cleanup rules.

Frequently Asked Questions about move-unit-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for Sui Move smart contracts?

Writing Sui Move unit tests requires following specific conventions like statement-style test names, using assert_eq for comparisons, and structuring test attributes. Correctly applying these patterns prevents brittle failures and ensures tests are reliable under CI.

How does expected_failure work in Sui Move testing?

The expected_failure attribute in Sui Move handles abort behavior by ensuring the test expects the correct abort code. You must specify the location parameter when aborts occur in another module and avoid dead-code cleanup after expected aborts to prevent misleading test results.

When should I use tx_context::dummy versus test_scenario in Move tests?

Use tx_context::dummy for simple, single-transaction test setups. Use test_scenario when your Move tests involve multi-transaction flows, shared objects, or testing the init function, as it provides the necessary environment for these complex interactions.

What is the best way to test authorization checks in Sui Move?

Testing authorization checks in Sui Move involves writing unit tests that assert expected_failure with specific abort codes when unauthorized users attempt restricted actions. This validates that your smart contract correctly rejects invalid transactions.

Why do my Sui Move unit tests fail with incorrect conventions?

Sui Move unit tests commonly fail due to incorrect conventions like missing the location parameter in expected_failure for cross-module aborts, wrong assertion styles, or improper test attribute merging. Fixing these patterns resolves brittle failures and missing diagnostics.