Saltar al contenido
Skillpedia
Pruebas40 mil · #7156

csharp-xunit

Qué hace

Esta herramienta te ayuda a escribir pruebas de código eficientes con XUnit, una librería muy popular para probar programas en C#. Enseña buenas prácticas tanto para las pruebas sencillas como para las pruebas con datos variados.

Cuándo usarla

  • ✓Cuando quieres asegurarte de que tu código C# funciona como se espera.
  • ✓Cuando creas pruebas que necesitan varios conjuntos de datos para ejecutarse.
  • ✓Para aprender a organizar y escribir pruebas de forma clara y reutilizable.

Link de la skill

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

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/github/awesome-copilot/blob/main/skills/csharp-xunit/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“¿Cómo puedo escribir una prueba para la función 'Add' que compruebe si 2 + 2 = 4 usando XUnit?”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La herramienta ofrece ejemplos y reglas para preparar tu proyecto de pruebas, estructurar las pruebas (separando la preparación, la acción y la verificación) y usar distintos tipos de pruebas, como las que reciben datos variados.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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
Preguntas frecuentes

¿Qué es una prueba unitaria?

Es una prueba pequeña que comprueba si una parte concreta de tu código (como una función) funciona correctamente de forma aislada.

¿Qué son las pruebas 'basadas en datos'?

Son pruebas que ejecutan la misma lógica varias veces, pero con un conjunto de datos distinto cada vez, para cubrir más situaciones.

¿Necesito saber mucho de C# para usar esto?

Es útil tener una comprensión básica de C# y de cómo funciona tu código, pero la herramienta está diseñada para guiarte en las buenas prácticas de las pruebas.

Detalles

Descripción original del autor

Get best practices for XUnit unit testing, including data-driven tests

repo: github/awesome-copilot

Popularidad

Estrellas en GitHub
40 mil
Posición en el ranking
#7156
Licencia
MIT
Actualizada
15/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas