csharp-xunit
하는 일
이 도구는 C# 프로그램을 테스트하는 인기 라이브러리인 XUnit으로 효율적인 코드 테스트를 작성하도록 돕습니다. 단순한 테스트와 다양한 데이터를 사용하는 테스트 모두에 대한 모범 사례를 가르칩니다.
사용하는 경우
- ✓C# 코드가 기대대로 작동하는지 확인하고 싶을 때.
- ✓실행하려면 여러 데이터 집합이 필요한 테스트를 만들 때.
- ✓테스트를 명확하고 재사용 가능하게 정리하고 작성하는 방법을 배우고 싶을 때.
스킬 링크
https://github.com/github/awesome-copilot/blob/main/skills/csharp-xunit/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“XUnit을 사용해 ‘Add’ 함수가 2 + 2 = 4를 반환하는지 확인하는 테스트를 어떻게 작성하나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
도구는 테스트 프로젝트 설정, 테스트 구조화(준비, 실행, 검증 분리), 그리고 다양한 데이터를 받는 테스트 같은 여러 유형의 테스트 사용법에 대한 예시와 규칙을 제공합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
XUnit Best Practices
Your goal is to help me write effective unit tests with XUnit, covering both standard and data-driven testing approaches.
Project Setup
- Use a separate test project with naming convention
[ProjectName].Tests - Reference Microsoft.NET.Test.Sdk, xunit, and xunit.runner.visualstudio packages
- Create test classes that match the classes being tested (e.g.,
CalculatorTestsforCalculator) - Use .NET SDK test commands:
dotnet testfor running tests
Test Structure
- No test class attributes required (unlike MSTest/NUnit)
- Use fact-based tests with
[Fact]attribute for simple tests - Follow the Arrange-Act-Assert (AAA) pattern
- Name tests using the pattern
MethodName_Scenario_ExpectedBehavior - Use constructor for setup and
IDisposable.Dispose()for teardown - Use
IClassFixture<T>for shared context between tests in a class - Use
ICollectionFixture<T>for shared context between multiple test classes
Standard Tests
- Keep tests focused on a single behavior
- Avoid testing multiple behaviors in one test method
- Use clear assertions that express intent
- Include only the assertions needed to verify the test case
- Make tests independent and idempotent (can run in any order)
- Avoid test interdependencies
Data-Driven Tests
- Use
[Theory]combined with data source attributes - Use
[InlineData]for inline test data - Use
[MemberData]for method-based test data - Use
[ClassData]for class-based test data - Create custom data attributes by implementing
DataAttribute - Use meaningful parameter names in data-driven tests
Assertions
- Use
Assert.Equalfor value equality - Use
Assert.Samefor reference equality - Use
Assert.True/Assert.Falsefor boolean conditions - Use
Assert.Contains/Assert.DoesNotContainfor collections - Use
Assert.Matches/Assert.DoesNotMatchfor regex pattern matching - Use
Assert.Throws<T>orawait Assert.ThrowsAsync<T>to test exceptions - Use fluent assertions library for more readable assertions
Mocking and Isolation
- Consider using Moq or NSubstitute alongside XUnit
- Mock dependencies to isolate units under test
- Use interfaces to facilitate mocking
- Consider using a DI container for complex test setups
Test Organization
- Group tests by feature or component
- Use
[Trait("Category", "CategoryName")]for categorization - Use collection fixtures to group tests with shared dependencies
- Consider output helpers (
ITestOutputHelper) for test diagnostics - Skip tests conditionally with
Skip = "reason"in fact/theory attributes
자주 묻는 질문
단위 테스트란 무엇인가요?
특정 코드 부분(함수 같은)이 다른 것과 떨어져서 올바르게 작동하는지 확인하는 작은 테스트입니다.
‘데이터 기반’ 테스트란 무엇인가요?
같은 로직을 여러 번 실행하되, 매번 다른 데이터 집합으로 더 많은 상황을 다루는 테스트입니다.
이걸 쓰려면 C#을 많이 알아야 하나요?
C#과 코드 작동 방식에 대한 기본 이해가 있으면 도움이 되지만, 이 도구는 테스트 모범 사례를 안내하도록 설계되었습니다.
상세 정보
작성자의 원본 설명
Get best practices for XUnit unit testing, including data-driven tests
repo: github/awesome-copilot
인기도
- GitHub 스타
- 40k
- 순위
- #7156
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
acquire-codebase-knowledge
40k에이전트가 기존 코드 프로젝트를 이해하고 문서화하도록 돕습니다. 새 구성원을 맞이하거나 아키텍처를 개괄적으로 파악할 때 유용합니다.
acreadiness-assess
40k에이전트가 프로젝트의 AI 준비 상태를 평가하고 보고서를 만들도록 합니다. 프로젝트가 AI 도구를 쓸 준비가 얼마나 되어 있는지 이해하는 데 유용합니다.
acreadiness-generate-instructions
40k에이전트가 평가 결과를 바탕으로 AI 도구를 위한 지침을 만들도록 돕습니다. AI가 코드와 상호작용하는 방식을 개선하고 확인된 공백을 메울 때 유용합니다.
acreadiness-policy
40k에이전트가 AI 프로젝트 평가를 위한 정책을 정의하거나 적용하도록 돕습니다. 프로젝트 평가 방식을 표준화하고 규정 준수를 보장할 때 유용합니다.
비슷한 스킬
test-driven-development
311k에이전트가 기능이나 수정을 만들기 전에 실패하는 테스트를 먼저 쓰고, 그것을 통과시키는 가장 작은 코드를 작성하도록 가르칩니다.
verification-before-completion
311k에이전트가 작업, 수정, 빌드가 완료되었거나 통과했다고 말하기 전에 실제 점검을 실행하고 결과를 읽도록 가르칩니다.
migrate-to-shoehorn
310k테스트 파일의 위험한 타입 캐스팅을 shoehorn 라이브러리로 바꿔, 테스트가 일부 데이터만 써도 타입 검사를 통과하도록 돕습니다.