dotnet-unit-tests
БесплатноБез исполняемых скриптовНе проверенUse for any question or task about .NET tests in C#, F# or VB.NET, including quick how-to questions and choosing between xUnit, NUnit and MSTest: Fact and…
от testland★ 18 звёзд на GitHubОб этом скилле
dotnet-unit-tests
Overview
Per xunit.net:
xUnit.net is the current .NET test standard (used by .NET Foundation
projects and Microsoft's own .NET runtime). v3 released 2024; v2 still
widely used in production. This skill covers xUnit as the default, with
NUnit and MSTest as references for existing conventions. Lifecycle scope
(configure / run / parameterize / fixtures / CI); test code hygiene is in
test-code-conventions (qa-test-review).
Choosing a framework
- Match the existing convention first. Grep sibling test projects'
.csprojfor<PackageReference Include="...">:xunit/xunit.v3→ xUnit;NUnit/NUnit3TestAdapter→ NUnit;MSTest/MSTest.TestFramework→ MSTest. If exactly one is present, match it - switching frameworks mid-solution forces a wholesale assertion rewrite for no quality gain. - New project on modern .NET (net6.0+) → xUnit: Microsoft's
testing docs list it as the community-focused default and
dotnet new xunitis a first-party template (learn.microsoft.com/dotnet/core/testing). - Legacy .NET Framework 4.x target → NUnit or MSTest (both span Framework 4.x and modern .NET) → references/nunit.md / references/mstest.md. MSTest also fits shops standardized on tight Visual Studio integration.
FluentAssertionsalready in deps → retain it regardless of framework (it auto-detects xUnit, NUnit, and MSTest) → references/fluentassertions.md - including the v8 commercial-license change.
Step 1 - Install
dotnet new xunit -n MyProjectTests
# Or in existing project:
dotnet add package xunit
dotnet add package xunit.runner.visualstudio
dotnet add package Microsoft.NET.Test.Sdk
Step 2 - First test
using Xunit;
public class CalculatorTests
{
[Fact]
public void Adds_TwoNumbers()
{
Assert.Equal(3, Calculator.Add(1, 2));
}
}
Run: dotnet test. Verify the run reports Passed! with the expected
test count; if it discovers 0 tests, confirm the class is public, the
method carries [Fact], and all three packages are installed.
Step 3 - Parametrized tests
Per xn-docs:
[Theory]
[InlineData(1, 2, 3)]
[InlineData(0, 0, 0)]
[InlineData(-1, 1, 0)]
public void Adds_VariousInputs(int a, int b, int expected)
{
Assert.Equal(expected, Calculator.Add(a, b));
}
// Method-based data source
public static IEnumerable<object[]> AddCases =>
new List<object[]> {
new object[] { 1, 2, 3 },
new object[] { 0, 0, 0 },
};
[Theory]
[MemberData(nameof(AddCases))]
public void Adds_FromMemberData(int a, int b, int expected) { ... }
[ClassData(typeof(AddTestData))] covers class-based sources
(IEnumerable<object[]> implementations). A [Theory] without a data
attribute never runs.
Step 4 - Skip + traits
[Fact(Skip = "Requires staging DB")]
public void SkippedTest() { }
[Fact]
[Trait("Category", "Integration")]
public void IntegrationTest() { }
// Filter: dotnet test --filter "Category=Integration"
Step 5 - Fixtures and parallelism
xUnit's lifecycle: constructor as setup, IDisposable.Dispose as
teardown - a new test-class instance per test. Shared setup scales up
through fixtures:
// Class fixture: shared across all tests in one class
public class DatabaseFixture : IDisposable {
public DbConnection Connection { get; }
public DatabaseFixture() { Connection = OpenConnection(); }
public void Dispose() { Connection.Close(); }
}
public class UserTests : IClassFixture<DatabaseFixture> {
private readonly DatabaseFixture _fixture;
public UserTests(DatabaseFixture fixture) { _fixture = fixture; }
}
// Collection fixture: shared across multiple test classes
[CollectionDefinition("DbCollection")]
public class DbCollection : ICollectionFixture<DatabaseFixture> { }
[Collection("DbCollection")]
public class TestsA { ... }
[Collection("DbCollection")]
public class TestsB { ... } // shares the same DatabaseFixture
By default xUnit runs collections in parallel; tests in the same collection run sequentially. Assembly-level tuning:
[assembly: CollectionBehavior(DisableTestParallelization = true)]
// or
[assembly: CollectionBehavior(MaxParallelThreads = 4)]
Pattern: DB-backed classes share one fixture via [Collection] (runs
sequentially against the shared connection) while pure-logic tests
parallelize freely.
Step 6 - Output (ITestOutputHelper)
xUnit suppresses Console.WriteLine in tests:
public class TestsWithOutput {
private readonly ITestOutputHelper _output;
public TestsWithOutput(ITestOutputHelper output) { _output = output; }
[Fact]
public void LogsContext() {
_output.WriteLine("Test running at {0}", DateTime.
Установить dotnet-unit-tests в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл dotnet-unit-tests?
Use for any question or task about .NET tests in C#, F# or VB.NET, including quick how-to questions and choosing between xUnit, NUnit and MSTest: Fact and Theory tables, fixtures and shared state between tests, parallel runs, mocking, async tests, output, and coverage with dotnet test. Has authoring conventions and anti-patterns for xUnit.net.
Как установить скилл dotnet-unit-tests?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dotnet-unit-tests запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic