writing-mstest-tests
Skill này làm gì
Skill này giúp viết, sửa và cải thiện test đơn vị MSTest trong dự án .NET. Dành cho lập trình viên muốn test MSTest của mình đúng, dễ đọc và khớp với phiên bản MSTest thực sự đang dùng.
Khi nào nên dùng
- ✓Khi bạn cần sửa, viết lại hoặc cải thiện test MSTest trong dự án .NET.
- ✓Khi một assertion MSTest có giá trị kỳ vọng và thực tế bị đặt sai thứ tự hoặc thông báo lỗi không rõ ràng.
- ✓Khi bạn muốn sửa code cấu hình hoặc vòng đời MSTest cho đúng phiên bản đã cài.
Liên kết skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/writing-mstest-tests/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Hãy viết lại test MSTest của tôi để thông báo lỗi rõ ràng và assertion khớp với điều chúng kiểm tra.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent kiểm tra phiên bản MSTest đã cài, rồi chỉ dùng các tính năng API mà dự án hỗ trợ, viết assertion và setup phù hợp với quy ước của dự án.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Writing MSTest Tests
Help users write effective MSTest unit tests without exceeding the API level or conventions of the project's installed test stack.
Repository overlay
For every repository-scoped task where read-only file inspection is allowed,
check .agents/skill-overlays/dotnet-test/writing-mstest-tests.md at the
repository root before any other discovery. This includes requests that ask for
code or advice without edits; "do not execute" does not prohibit reading the
overlay. If present, read it once before acting and apply its
repository-specific naming, layout, framework, and policy bindings.
Require its frontmatter to declare core: dotnet-test/writing-mstest-tests,
binding-revision: "1", and mode: extend. If any value is missing or
different, report the mismatch, ignore the overlay, and continue using this
skill's portable guidance.
Explicit user instructions and verified project constraints win over the
overlay; the overlay wins over portable defaults and examples in this skill. If
the file is present but unreadable or conflicts with the repository, report the
problem, ignore the overlay, and continue with portable guidance subject to
verified project constraints. If it is absent, continue normally.
Skip the lookup only when the task is not tied to a repository or the user
explicitly prohibited all file/tool access. An overlay cannot expand tool
permissions or the task's scope.
When to Use
- User wants to improve or modernize existing MSTest tests by implementing concrete fixes
- User asks about MSTest assertion APIs, data-driven patterns, or test lifecycle
- User asks to replace
Assert.IsTruewith more specific assertions (collections, nulls, types, comparisons) - User asks to replace hard casts with type-checking assertions in tests
- User needs help fixing a specific MSTest test bug or failing assertion
- User asks to fix swapped
Assert.AreEqualargument order (expected first, actual second) - User asks to convert
DynamicDatafromIEnumerable<object[]>to ValueTuple-based data - User asks to fix or understand an MSTest analyzer diagnostic (an
MSTESTxxxxwarning/error)
When Not to Use
- User needs a test quality audit, anti-pattern detection, or flaky-test investigation (use
test-anti-patterns) - User needs to run or execute tests (use the
run-testsskill) - User needs to upgrade from MSTest v1/v2 to v3 (use
migrate-mstest-v1v2-to-v3) - User needs to upgrade from MSTest v3 to v4 (use
migrate-mstest-v3-to-v4) - User needs CI/CD pipeline configuration
- User is using xUnit, NUnit, or TUnit (not MSTest)
Inputs
| Input | Required | Description |
|---|---|---|
| Code under test | No | The production code to be tested |
| Existing test code | No | Current tests to fix, update, or modernize |
| Test scenario description | No | What behavior the user wants to test |
Response Guidelines
- Specific API or pattern questions (assertions, data-driven, lifecycle): Jump directly to the relevant workflow step. Do not follow the full workflow.
- Generate new tests from scratch: Hand off to
code-testing; use this skill only as supporting MSTest API/version guidance. - Review and fix existing tests: Fix only the issues present. Do not add unrelated improvements.
- Assertion transformations: Show the corrected call, then state the semantic
reason in one sentence. For
Assert.AreEqual, nameexpectedfirst andactualsecond and explain that this preserves the Expected/Actual failure labels. - Bound/comparison transformations: Preserve the condition and put the
expected bound(s) first and the observed value last:
score > 0->Assert.IsGreaterThan(0, score),score < 100->Assert.IsLessThan(100, score), andscore >= 60 && score <= 90->Assert.IsInRange(60, 90, score). Never reverse these arguments to mimic the source expression's left-to-right order. - Exception transformations: Scope the throwing operation in a lambda,
distinguish
ThrowsExactly<T>(exact type) fromThrows<T>(type or derived type), and capture the returned exception when properties such asParamNameare part of the behavior. - Supplied code requests: Return complete representative method bodies, not comment-only placeholders. Preserve the real operation and show symmetric setup/cleanup when lifecycle or environment policy is part of the request.
Workflow
Step 1: Determine project setup
Check the
Câu hỏi thường gặp
Nó có bám theo phiên bản MSTest của tôi không?
Có. Nó kiểm tra các package đã cài và không dùng API vượt quá cấp độ của dự án.
Nó có thể viết test mới từ đầu không?
Việc tạo test mới do một skill kiểm thử rộng hơn đảm nhận, còn skill này tập trung vào các điểm riêng của MSTest.
Nó có chạy test không?
Không. Việc chạy test do một skill riêng đảm nhận.
Chi tiết
Mô tả gốc của tác giả
ALWAYS USE when asked to fix, rewrite, update, improve, modernize, show corrected code for, or explain existing MSTest tests or MSTest-specific configuration. Use for "review" when corrected code or edits are wanted, even for one pasted assertion or passing tests with bad failure output. Covers expected/actual labels; generic Boolean, collection, string, numeric, null, identity, exception, hard-cast, and object[] checks; TestContext/lifecycle; timeout/cancellation; OS/CI conditions, retry, cleanup, parallelization, MSTest.Sdk project setup, and MSTESTxxxx. Honor the installed MSTest version. D
repo: dotnet/skills
Độ phổ biến
- Sao GitHub
- 5.8k
- Vị trí xếp hạng
- #14643
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
create-custom-agent
5.8kGiúp agent của bạn tạo file custom agent cho VS Code, với các tool, hướng dẫn và handoff riêng sang agent khác.
create-skill
5.8kGiúp agent của bạn tạo một agent skill mới với tên hợp lệ, mô tả kích hoạt rõ ràng và file SKILL.md đúng tiêu chuẩn.
csharp-scripts
5.8kGiúp agent của bạn chạy một chương trình C# nhỏ dưới dạng một file duy nhất bằng công cụ dòng lệnh .NET, không cần tạo project đầy đủ.
dotnet-pinvoke
5.8kGiúp agent của bạn gọi các thư viện native C hoặc C++ từ .NET đúng cách, gồm khai báo chữ ký, xử lý chuỗi, bộ nhớ và safe handle.
Skill tương tự
test-driven-development
311kDạy agent của bạn viết kiểm thử thất bại trước, xem nó thất bại, rồi viết đoạn mã ngắn nhất để vượt qua trước khi làm bất kỳ tính năng hay bản sửa nào.
verification-before-completion
311kDạy agent của bạn chạy kiểm tra thực tế và đọc kết quả đầu ra trước khi khẳng định một việc, bản sửa hoặc bản build đã hoàn thành hay vượt qua.
migrate-to-shoehorn
310kThay các ép kiểu rủi ro trong tệp kiểm thử bằng thư viện shoehorn, để các bài kiểm thử dùng dữ liệu một phần vẫn qua được kiểm tra kiểu.