본문으로 건너뛰기
Skillpedia
테스트40k · #7156

csharp-xunit

하는 일

이 도구는 C# 프로그램을 테스트하는 인기 라이브러리인 XUnit으로 효율적인 코드 테스트를 작성하도록 돕습니다. 단순한 테스트와 다양한 데이터를 사용하는 테스트 모두에 대한 모범 사례를 가르칩니다.

사용하는 경우

  • ✓C# 코드가 기대대로 작동하는지 확인하고 싶을 때.
  • ✓실행하려면 여러 데이터 집합이 필요한 테스트를 만들 때.
  • ✓테스트를 명확하고 재사용 가능하게 정리하고 작성하는 방법을 배우고 싶을 때.

스킬 링크

https://github.com/github/awesome-copilot/blob/main/skills/csharp-xunit/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/csharp-xunit/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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., CalculatorTests for Calculator)
  • Use .NET SDK test commands: dotnet test for 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.Equal for value equality
  • Use Assert.Same for reference equality
  • Use Assert.True/Assert.False for boolean conditions
  • Use Assert.Contains/Assert.DoesNotContain for collections
  • Use Assert.Matches/Assert.DoesNotMatch for regex pattern matching
  • Use Assert.Throws<T> or await 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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬