Agent skill

Testing Guide

by mobazha in mobazha/mobazha-unified

Guide for writing unit tests (Vitest), integration tests, and E2E tests (Playwright) following Mobazha project conventions.

MPL-2.0Auto-check passedTesting & QA

Install Testing Guide

skills CLI
$ npx skills add mobazha/mobazha-unified --skill testing-guide -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install mobazha/mobazha-unified testing-guide --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/mobazha/mobazha-unified.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.cursor/skills/testing-guide .claude/skills/testing-guide && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
testing-guide
GitHub stars
165
Token cost
~1.7k tokens
SKILL.md length
150 words
Files
1
Skills in repo
29
Repo updated
First seen
Licence
MPL-2.0

At a glance

Guide for writing unit tests (Vitest), integration tests, and E2E tests (Playwright) following Mobazha project conventions.

  • Setting up test files
  • SKILL.md covers 测试金字塔, 技术栈, 单元测试模式 and 集成测试模式, plus 4 more sections
  • Calls pnpm
  • Asking about testing strategies

What it does

Testing Guide is an agent skill from mobazha/mobazha-unified. Guide for writing unit tests (Vitest), integration tests, and E2E tests (Playwright) following Mobazha project conventions. Use when writing tests, setting up test files, or asking about testing strategies, "写测试", "测试", "单元测试", "E2E测试", "集成测试", "测试覆盖率".

Its SKILL.md is about 1.7k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Testing & QA, covering Unit testing, End-to-end testing and Browser testing. It works with Playwright and Vitest. The repository describes itself as: Open-source commerce frontend for storefronts, marketplaces, checkout, and seller management. The licence is MPL-2.0.

When your agent uses it

  • Setting up test files
  • Asking about testing strategies

Example prompts

  • “/testing-guide”

What it can do on your machine

Read from SKILL.md and the folder at commit 156c699. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • pnpm

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pnpm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Testing Guide loads about 1.7k tokens when it runs. Until then it costs about 67 tokens; SKILL.md has 150 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~67
When it runs · the whole SKILL.md, loaded when a task matches
~1.7k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from mobazha/mobazha-unified at commit 156c699, republished under its MPL-2.0 licence (© mobazha). 150 words, ~1,661 tokens.

Download SKILL.mdSave it as .claude/skills/testing-guide/SKILL.md (or your agent's skills folder).
name
testing-guide
description
Guide for writing unit tests (Vitest), integration tests, and E2E tests (Playwright) following Mobazha project conventions. Use when writing tests, setting up test files, or asking about testing strategies, "写测试", "测试", "单元测试", "E2E测试", "集成测试", "测试覆盖率".

测试编写指南

Mobazha 项目的测试策略、模式和最佳实践。

测试金字塔

         ┌─────────┐
         │  E2E    │  少量关键路径 (Playwright)
        ┌┴─────────┴┐
        │ 集成测试   │  API + Store 联动 (Vitest)
       ┌┴───────────┴┐
       │  单元测试    │  hooks/utils/transforms (Vitest)
       └─────────────┘

覆盖率目标:核心逻辑(hooks、utils、transforms)> 80%

技术栈

层级工具目录
单元测试Vitest + jsdompackages/core/__tests__/
集成测试Vitestpackages/core/__tests__/integration/
E2E 测试Playwrightapps/web/e2e/

单元测试模式

文件组织
packages/core/__tests__/
├── setup.ts                    # 全局 setup(localStorage mock 等)
├── utils/
│   └── performance.test.ts     # 工具函数测试
├── services/
│   └── api/
│       └── orders.test.ts      # API 服务测试
└── i18n/
    └── i18n.test.ts            # i18n 测试
Hook 测试模板
typescript
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { renderHook, act } from '@testing-library/react';

describe('useOrderDetail', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it('应返回订单详情数据', async () => {
    const { result } = renderHook(() => useOrderDetail('order-123'));

    await waitFor(() => {
      expect(result.current.displayOrder).toBeDefined();
      expect(result.current.isLoading).toBe(false);
    });
  });

  it('应正确处理错误状态', async () => {
    vi.mocked(ordersApi.getOrder).mockRejectedValue(new Error('网络错误'));

    const { result } = renderHook(() => useOrderDetail('invalid'));

    await waitFor(() => {
      expect(result.current.error).toBeTruthy();
    });
  });
});
Transform 函数测试模板
typescript
describe('transformCoreOrder', () => {
  it('应将买家角色正确映射', () => {
    const result = transformCoreOrder({
      coreOrder: mockOrder,
      currentUserPeerID: 'buyer-peer-id',
    });

    expect(result.userRole).toBe('buyer');
    expect(result.canDispute).toBe(true);
  });
});
Store 测试模板
typescript
import { act } from '@testing-library/react';

describe('useCartStore', () => {
  beforeEach(() => {
    // 重置 store
    useCartStore.setState({ items: [], error: null });
  });

  it('应正确添加商品', () => {
    act(() => {
      useCartStore.getState().addItem(mockItem);
    });

    expect(useCartStore.getState().items).toHaveLength(1);
    expect(useCartStore.getState().getItemCount()).toBe(1);
  });
});

集成测试模式

项目使用 skipIfNoIntegration() 辅助函数,需要后端运行时才执行:

typescript
import { skipIfNoIntegration } from '../setup';

describe('Orders Integration', () => {
  skipIfNoIntegration();

  it('应完成完整的购买流程', async () => {
    // 创建订单
    const order = await ordersApi.createOrder(mockPurchase);
    expect(order.id).toBeDefined();

    // 确认订单
    await ordersApi.confirmOrder(order.id);
    // ...
  });
});

E2E 测试模式 (Playwright)

typescript
import { test, expect } from '@playwright/test';

test.describe('首页', () => {
  test('应正确显示导航栏', async ({ page }) => {
    await page.goto('/');

    await expect(page.getByRole('navigation')).toBeVisible();
    await expect(page.getByTestId('search-input')).toBeVisible();
  });

  test('响应式:移动端应显示汉堡菜单', async ({ page }) => {
    await page.setViewportSize({ width: 375, height: 667 });
    await page.goto('/');

    await expect(page.getByTestId('mobile-menu-button')).toBeVisible();
  });
});
E2E 关键规则
  • 必须使用 data-testid 定位元素,禁止 CSS 选择器
  • 使用 getByRole、getByText 作为辅助定位
  • 每个测试必须独立,不依赖其他测试的状态
视觉回归测试

项目维护桌面端和移动端的视觉快照测试,分为 Public(公开页面)和 Authenticated(已登录页面)两组:

测试文件设备用途
desktop-visual.spec.tsChromium 1280×720桌面端视觉快照
mobile-visual.spec.tsMobile Chrome (Pixel 5)移动端视觉快照
ux-audit.spec.tsChromium 1280×720桌面端 UX 审计(深度)
mobile-ux-audit.spec.tsiPhone 12 390×844移动端 UX 审计
E2E Fixtures(e2e/fixtures/)
文件职责
auth.tsCasdoor 登录 + Onboarding 自动完成 + loginAndSetup()
mock-api-routes.tsMock API 响应(订单/通知/搜索/商品详情/地址),确保已登录页面有数据显示
seed-visual-data.ts通过 API 创建测试商品 + 注入购物车到 localStorage

已登录页面测试模式:

typescript
import { loginAndSetup } from './fixtures/auth';
import { mockOrdersAPI, mockNotificationsAPI } from './fixtures/mock-api-routes';

test.describe('Authenticated Pages', () => {
  test.beforeAll(async ({ browser }) => {
    const page = await browser.newPage();
    await loginAndSetup(page);
    // 保存认证状态...
  });

  test('orders page', async ({ page }) => {
    await mockOrdersAPI(page); // 拦截 API 返回 mock 数据
    await page.goto('/orders/purchases');
    await expect(page).toHaveScreenshot('orders-purchases.png');
  });
});

Mock 最佳实践:

  • Mock 函数仅拦截 GET 请求,非 GET 通过 route.fallback()
  • 认证状态通过 storageState 在测试间共享,避免重复登录
运行视觉测试
bash
# 桌面端
pnpm --filter @mobazha/web exec playwright test desktop-visual --project=chromium

# 移动端
pnpm --filter @mobazha/web exec playwright test mobile-visual --project="Mobile Chrome"

# 更新快照
pnpm --filter @mobazha/web exec playwright test desktop-visual --update-snapshots

运行命令

bash
# 单元测试
pnpm --filter @mobazha/core test

# 带覆盖率
pnpm --filter @mobazha/core test -- --coverage

# E2E 测试
pnpm --filter @mobazha/web test:e2e

# 单个文件
pnpm --filter @mobazha/core test -- orderTransform.test.ts

Mock 策略

场景方式
API 调用vi.mock('@mobazha/core/services/api')
Zustand StoreuseStore.setState({...}) 直接设置状态
localStorage全局 setup 中已 mock
网络请求优先用 vi.mock,复杂场景用 MSW
时间相关vi.useFakeTimers()

快速检查清单

  • 新增 hook/util 是否有对应测试文件?
  • 测试描述是否清晰(describe('when X') → it('should Y'))?
  • 是否测试了错误路径和边界情况?
  • Mock 是否在 beforeEach 中重置?
  • 是否避免了 test.skip 不带注释?

© mobazha, MPL-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .cursor/skills/testing-guide of mobazha/mobazha-unified.

Open the folder on GitHubat commit 156c699

Compare with similar skills

Testing Guide next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Testing Guide compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Testing Guide this skillmobazha/mobazha-unified165—~1.7kAutomated safety check: PassMPL-2.0
Angular TestingKilo-Org/kilo-marketplace189—~2.9kAutomated safety check: PassMIT
Web Testing with Playwright and Vitestwithkynam/vibecode-pro-max-kit1.1k—~892Automated safety check: PassApache-2.0
Dotnet Testingnovotnyllc/dotnet-artisan233—~972Automated safety check: PassMIT
Vue Testing Best PracticesJetBrains/skills3637 repos~563Automated safety check: PassMIT
Front End Testingcitypaul/.dotfiles739—~6.2kAutomated safety check: PassCustom licence

Similar skills

  • Angular Testing

    Kilo-Org/kilo-marketplace

    Write unit and integration tests for Angular v20+ applications using Vitest or Jasmine with TestBed and modern testing patterns.

    189 GitHub stars~2.9k tokensUpdated 9 days ago
    Testing & QAAuto-check passed
  • Web Testing with Playwright and Vitest

    withkynam/vibecode-pro-max-kit

    Covers web testing from unit to E2E, load, visual, accessibility and security checks, with Playwright, Vitest and k6 guides plus a Playwright setup script.

    1.1k GitHub stars~892 tokensUpdated 3 mo ago
    Testing & QAAuto-check passed
  • Dotnet Testing

    novotnyllc/dotnet-artisan

    Defines .NET test strategy and implementation patterns across xUnit v3 (Facts, Theories, fixtures, IAsyncLifetime), integration testing (WebApplicationFactory, Testcontainers), Aspire testing…

    233 GitHub stars~972 tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • Official

    A skill your agent uses for Vue.js testing. An agent skill from JetBrains/skills.

    363 GitHub starsUsed in 7 repos~563 tokens
    Testing & QAAuto-check passed
  • Front End Testing

    citypaul/.dotfiles

    Behavior-driven UI testing patterns across Vitest Browser Mode, Playwright E2E evidence boundaries, and DOM Testing Library.

    739 GitHub stars~6.2k tokensUpdated 5 days ago
    Testing & QAAuto-check passed
  • Designing Tests

    CloudAI-X/claude-workflow-v2

    Designs and implements testing strategies for any codebase. An agent skill from CloudAI-X/claude-workflow-v2.

    1.4k GitHub starsUsed in 1 repo~1.5k tokens
    Testing & QAAuto-check passed

More from mobazha/mobazha-unified

All 29 skills in this repo
  • A11y Guide

    mobazha/mobazha-unified

    Accessibility guide for Mobazha following WCAG 2.1 AA standards including color contrast, reduced motion, ARIA patterns, keyboard navigation, focus management, and screen reader testing.

    165 GitHub stars~1.4k tokensUpdated 4 days ago
    Auto-check passed
  • API Reference

    mobazha/mobazha-unified

    Look up Mobazha backend API endpoints, request/response formats, and field mappings.

    165 GitHub stars~1.7k tokensUpdated 4 days ago
    Auto-check passed
  • Code Review

    mobazha/mobazha-unified

    Review code for quality, architecture consistency, and adherence to Mobazha project standards using confidence-based filtering.

    165 GitHub stars~464 tokensUpdated 4 days ago
    Auto-check passed
  • Code Simplifier

    mobazha/mobazha-unified

    Simplify and refine recently written code for clarity, consistency, and maintainability while preserving all functionality.

    165 GitHub stars~601 tokensUpdated 4 days ago
    Auto-check passed
  • Commit Helper

    mobazha/mobazha-unified

    Generate commit messages and run pre-commit validation following Mobazha conventions.

    165 GitHub stars~735 tokensUpdated 4 days ago
    Auto-check passed
  • Component Dev

    mobazha/mobazha-unified

    Create and modify UI components following Mobazha conventions including directory structure, spacing standards, accessibility, and testing.

    165 GitHub stars~638 tokensUpdated 4 days ago
    Auto-check passed

Categories

Questions about Testing Guide

What does Testing Guide do?

Guide for writing unit tests (Vitest), integration tests, and E2E tests (Playwright) following Mobazha project conventions. Testing Guide is an agent skill from mobazha/mobazha-unified. Guide for writing unit tests (Vitest), integration tests, and E2E tests (Playwright) following Mobazha project conventions.

When should I use Testing Guide?

Testing Guide fits situations like: setting up test files; asking about testing strategies.

How do I install Testing Guide in Claude Code?

Run `npx skills add mobazha/mobazha-unified --skill testing-guide -a claude-code`. Or copy the skill folder (.cursor/skills/testing-guide in mobazha/mobazha-unified) into .claude/skills/testing-guide in your project. Claude Code loads it when a task matches its description.

How do I install Testing Guide in Codex?

Run `npx skills add mobazha/mobazha-unified --skill testing-guide -a codex`. Or copy the skill folder (.cursor/skills/testing-guide in mobazha/mobazha-unified) into .agents/skills/testing-guide in your project. Codex loads it when a task matches its description.

Can I use Testing Guide in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add mobazha/mobazha-unified --skill testing-guide -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/testing-guide, .gemini/skills/testing-guide, .github/skills/testing-guide and .opencode/skills/testing-guide in your project.

What does Testing Guide need to run?

Going by SKILL.md and its folder, Testing Guide needs the command-line tools its instructions call (pnpm).

Does Testing Guide access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Testing Guide safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Testing Guide use?

Testing Guide is published under the MPL-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Testing Guide use?

About 1.7k tokens (SKILL.md is roughly 6.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Testing Guide?

Skills that share tags, products or a category with Testing Guide: Angular Testing (Kilo-Org/kilo-marketplace, 189 stars), Web Testing with Playwright and Vitest (withkynam/vibecode-pro-max-kit, 1.1k stars), Dotnet Testing (novotnyllc/dotnet-artisan, 233 stars) and Vue Testing Best Practices (JetBrains/skills, 363 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Testing Guide?

mobazha (a GitHub organization) maintains it in mobazha/mobazha-unified, which has 165 GitHub stars. The repository holds 29 skills in this directory. The repository was last updated on October 3, 2026.

Source: mobazha/mobazha-unified on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.