agentleFS
anhtesteranhtester/codex-testing-kit/.agents/skills/generate-test-data/SKILL.md

generate-test-data

Skill28 starsChanged 4 months agoMITView on GitHub

Sinh test data có cấu trúc, unique, traceable cho test cases. Hỗ trợ UI forms, API payloads, data-driven tests.

  • Reads credentials
  • Deletes or force-pushes

The file

Files
SKILL.md

$generate-test-data — Sinh Test Data Có Cấu Trúc

User cung cấp feature/module hoặc test cases cần sinh data. AI phân tích fields, constraints, sinh bộ data đầy đủ (positive, negative, boundary, edge cases) với format sẵn sàng sử dụng.

BẮT BUỘC (MANDATORY): Trước khi bắt đầu, PHẢI nạp và đọc kỹ:

  • Skill: .agents/skills/test-data-generator/SKILL.md — Quy tắc sinh data
  • Rule: .agents/rules/automation_rules.md — Section Test Data

Input cần từ User

InputBắt buộcMô tả
Feature / Module✅VD: "Form đăng ký", "API Create User", "Trang Login"
Fields cần data⚠️ Nên cóDanh sách fields + constraints. Nếu không có → AI tự phân tích từ DOM/Spec
URL trang / Swagger spec❌Nếu có → AI inspect DOM/Spec để lấy validation rules chính xác
Test cases❌Nếu đã có test cases → AI sinh data match từng TC
Output format❌json (mặc định), csv, markdown table, code (TypeScript/Java/Python)
Ngôn ngữ data❌Tiếng Việt / Tiếng Anh (mặc định: theo context)

Các bước thực hiện

Bước 1: Phân tích Fields & Constraints

  1. Xác định nguồn thông tin:

    NguồnCách lấyƯu tiên
    User cung cấp trực tiếpĐọc từ input⭐ Cao nhất
    DOM thực tế (UI form)browser_navigate → browser_snapshot → phân tích input fields⭐ Cao
    Swagger/OpenAPI specread_url_content → parse schema + constraints⭐ Cao
    Test cases đã cóĐọc test steps → trích xuất fieldsTrung bình
    Đoán từ tên moduleDựa trên kinh nghiệm domain⭐ Thấp nhất
  2. Với mỗi field, xác định:

    AttributeVí dụ
    Tên fieldemail, password, name, phone
    Kiểu dữ liệustring, number, boolean, date, file, enum
    Required?Bắt buộc hay tùy chọn
    Validation rulesmin/maxLength, pattern/regex, format (email, phone), unique
    Giá trị mặc địnhNếu có
    Enum valuesVD: status = ["AVAILABLE", "UNAVAILABLE"]
    Quan hệ phụ thuộcVD: password_confirm phải khớp password
  3. Trình bày bảng Fields cho User xác nhận (CHECKPOINT ⏸️):

    | # | Field | Type | Required | Constraints | Notes |
    |---|-------|------|----------|-------------|-------|
    | 1 | email | string | ✅ | format: email, unique | Dùng để login |
    | 2 | password | string | ✅ | minLength: 6 | |
    | 3 | name | string | ✅ | maxLength: 100 | |
    | 4 | phone | string | ❌ | pattern: /^0[0-9]{9}$/ | 10 chữ số, bắt đầu bằng 0 |

    Chờ User xác nhận hoặc bổ sung constraints trước khi sang Bước 2.


Bước 2: Sinh Test Data theo 4 Categories

Với mỗi field đã xác định, sinh data theo bảng sau:

2A. Positive Data (Happy Path)

  • Giá trị hợp lệ, đúng format, trong constraints
  • Tất cả required fields được điền
  • Dữ liệu phải unique + traceable

Format unique data:

<prefix>_<testName>_<timestamp>

Ví dụ:

email:    auto_register_1712049200@test.com
username: user_login_1712049200
code:     TC_BOOK_1712049200

2B. Negative Data

LoạiMô tảVí dụ
Missing requiredBỏ trống field bắt buộcemail: ""
Invalid formatSai formatemail: "not-an-email"
Invalid typeSai kiểu dữ liệuprice: "abc" (expect number)
DuplicateGiá trị đã tồn tạiemail: "existing@test.com"
Invalid charactersKý tự không được phépname: "<script>alert(1)</script>"
Wrong relationshipVi phạm quan hệ fieldspassword_confirm ≠ password

2C. Boundary Values

LoạiMô tảVí dụ (field có minLength=6, maxLength=20)
MinĐúng bằng min"abcdef" (6 chars)
Min - 1Dưới min"abcde" (5 chars)
MaxĐúng bằng max"a" * 20 (20 chars)
Max + 1Vượt max"a" * 21 (21 chars)
EmptyChuỗi rỗng""
ZeroSố 0 (cho number fields)0
NegativeSố âm (cho number fields)-1

2D. Edge Cases

LoạiMô tảVí dụ
UnicodeKý tự đặc biệt Unicode"Nguyễn Văn 🎉"
Very longChuỗi cực dài"a" * 10000
WhitespaceKhoảng trắng đầu/cuối" email@test.com "
SQL injectionPattern SQL injection"'; DROP TABLE users; --"
HTML tagsHTML trong text field"<b>bold</b><img src=x onerror=alert(1)>"
Null/undefinedGiá trị nullnull
Special numbersSố đặc biệt0.1 + 0.2, Number.MAX_SAFE_INTEGER, NaN
Date edgeNgày đặc biệt"2024-02-29" (năm nhuận), "2024-12-31", "1970-01-01"

Bước 3: Đóng gói Output

Trả kết quả theo format User yêu cầu (mặc định: JSON):

Format JSON (mặc định)

{
  "module": "User Registration",
  "totalDataSets": 15,
  "fields": ["email", "password", "name", "phone"],
  "positive": [
    {
      "id": "POS_01",
      "description": "Đăng ký thành công với tất cả fields hợp lệ",
      "data": {
        "email": "auto_register_1712049200@test.com",
        "password": "Test@12345",
        "name": "Auto User Register",
        "phone": "0912345001"
      },
      "expectedResult": "Tạo tài khoản thành công, status 201"
    }
  ],
  "negative": [
    {
      "id": "NEG_01",
      "description": "Email trống",
      "data": { "email": "", "password": "Test@12345", "name": "Test User" },
      "expectedResult": "Lỗi validation: Email is required",
      "targetField": "email",
      "negativeType": "missing_required"
    },
    {
      "id": "NEG_02",
      "description": "Email sai format",
      "data": { "email": "not-email", "password": "Test@12345", "name": "Test User" },
      "expectedResult": "Lỗi validation: Invalid email format",
      "targetField": "email",
      "negativeType": "invalid_format"
    }
  ],
  "boundary": [
    {
      "id": "BND_01",
      "description": "Password đúng min length (6 chars)",
      "data": { "email": "auto_bnd01_1712049200@test.com", "password": "Abc@12", "name": "Test User" },
      "expectedResult": "Thành công",
      "targetField": "password",
      "boundaryType": "min"
    }
  ],
  "edgeCases": [
    {
      "id": "EDGE_01",
      "description": "Name chứa Unicode tiếng Việt + emoji",
      "data": { "email": "auto_edge01_1712049200@test.com", "password": "Test@12345", "name": "Nguyễn Văn 🎉" },
      "expectedResult": "Thành công — hệ thống chấp nhận Unicode",
      "targetField": "name",
      "edgeType": "unicode"
    }
  ]
}

Format Markdown Table

| ID | Category | Description | email | password | name | Expected Result |
|----|----------|-------------|-------|----------|------|-----------------|
| POS_01 | Positive | Đăng ký thành công | auto_reg@test.com | Test@12345 | Auto User | 201 Created |
| NEG_01 | Negative | Email trống | (empty) | Test@12345 | Test User | 422: Email is required |
| BND_01 | Boundary | Password min length | auto_bnd@test.com | Abc@12 | Test User | 201 Created |

Format Code (TypeScript example)

// test-data/registration.data.ts
export const registrationData = {
  positive: {
    email: `auto_register_${Date.now()}@test.com`,
    password: 'Test@12345',
    name: 'Auto User Register',
    phone: '0912345001',
  },
  negative: {
    emptyEmail: { email: '', password: 'Test@12345', name: 'Test' },
    invalidEmail: { email: 'not-email', password: 'Test@12345', name: 'Test' },
    shortPassword: { email: `auto_neg_${Date.now()}@test.com`, password: '123', name: 'Test' },
  },
  boundary: {
    minPassword: { email: `auto_bnd_${Date.now()}@test.com`, password: 'Abc@12', name: 'Test' },
    maxName: { email: `auto_bnd_${Date.now()}@test.com`, password: 'Test@12345', name: 'A'.repeat(100) },
  },
};

Data Rules (BẮT BUỘC)

#RuleMô tả
1UniqueKhông trùng lặp trong test suite — dùng timestamp/random
2TraceableCó thể truy ngược test nào sinh ra data — dùng prefix + test name
3No real PIIKHÔNG dùng dữ liệu cá nhân thật (số CCCD, email thật, SĐT thật)
4Respect constraintsData phải tuân theo validation rules đã phân tích
5Include expectedResultMỗi data set PHẢI có expected result để dùng cho assertion
6Deterministic khi cầnCùng seed → cùng data (cho reproducible tests)

NGHIÊM CẤM

❌ Không được làm✅ Thay thế đúng
Dùng placeholder (email hợp lệ, mã số hợp lệ)Giá trị cụ thể: auto_tc01@test.com, KH-2026-0012
Hardcode data trùng lặp giữa các testRandom data với prefix + timestamp
Dùng dữ liệu cá nhân thậtData giả lập: auto_*@test.com
Chỉ sinh positive dataBắt buộc cả 4 categories: Positive + Negative + Boundary + Edge
Sinh data không có expected resultMỗi data set PHẢI nêu rõ expected result
Đoán validation rules không kiểm traInspect DOM/Spec hoặc hỏi User
Đọc .env để lấy credentialsHỏi User hoặc dùng placeholder [FROM_ENV]

Checklist cuối

  • Đã phân tích đầy đủ fields + constraints
  • User đã xác nhận bảng fields trước khi sinh data
  • Data có đủ 4 categories (Positive, Negative, Boundary, Edge Cases)
  • Mỗi data set có expected result rõ ràng
  • Data unique + traceable (prefix + timestamp/random)
  • Không chứa real PII
  • Format output đúng yêu cầu User (JSON/CSV/Markdown/Code)
  • Boundary values đúng theo constraints (min, min-1, max, max+1)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.