本文へスキップ
Skillpedia
テスト5.8k · #14628

filter-syntax

できること

この参考資料は、一般的なフレームワークで、実行する.NETのテストを選ぶフィルターの書き方を説明します。テストの一部だけを実行したい開発者向けです。

使う場面

  • ✓.NETのテストの一部、たとえば一つのクラスや一つのカテゴリだけを実行したいとき。
  • ✓統合テストや遅いテストを、テストの実行から除外したいとき。
  • ✓VSTestの構文からMicrosoft.Testing.Platformの構文に、フィルターを変換する必要があるとき。

スキルのリンク

https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/filter-syntax/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/filter-syntax/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“MSTestプロジェクトで統合テストだけを実行し、遅いテストは飛ばすにはどうすればよいですか?”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントはテストプラットフォームとフレームワークを特定し、正しいプロパティ名と演算子(containsや不等号など)を使ってフィルターを書きます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Test Filter Syntax Reference

Filter syntax depends on the platform and test framework.

VSTest filters (MSTest, xUnit v2, NUnit on VSTest)

dotnet test --filter <EXPRESSION>

Expression syntax: <Property><Operator><Value>[|&<Expression>]

Operators:

Operator Meaning
= Exact match
!= Not exact match
~ Contains
!~ Does not contain

Combinators: | (OR), & (AND). Parentheses for grouping: (A|B)&C

Supported properties by framework:

Framework Properties
MSTest FullyQualifiedName, Name, ClassName, Priority, TestCategory
xUnit FullyQualifiedName, DisplayName, Traits
NUnit FullyQualifiedName, Name, Priority, TestCategory

An expression without an operator is treated as FullyQualifiedName~<value>.

Examples (VSTest):

# Run tests whose name contains "LoginTest"
dotnet test --filter "Name~LoginTest"

# Run a specific test class
dotnet test --filter "ClassName=MyNamespace.MyTestClass"

# Run tests in a category
dotnet test --filter "TestCategory=Integration"

# Exclude a category
dotnet test --filter "TestCategory!=Slow"

# Combine: class AND category
dotnet test --filter "ClassName=MyNamespace.MyTestClass&TestCategory=Unit"

# Either of two classes
dotnet test --filter "ClassName=MyNamespace.ClassA|ClassName=MyNamespace.ClassB"

MTP filters — MSTest and NUnit

MSTest and NUnit on MTP use the same --filter syntax as VSTest (same properties, operators, and combinators). The only difference is how the flag is passed:

# .NET SDK 8/9 (after --)
dotnet test -- --filter "Name~LoginTest"

# .NET SDK 10+ (direct)
dotnet test --filter "Name~LoginTest"

MTP filters — xUnit (v3)

xUnit v3 on MTP uses framework-specific filter flags instead of the generic --filter expression:

Flag Description
--filter-class "name" Run all tests in a given class
--filter-not-class "name" Exclude all tests in a given class
--filter-method "name" Run a specific test method
--filter-not-method "name" Exclude a specific test method
--filter-namespace "name" Run all tests in a namespace
--filter-not-namespace "name" Exclude all tests in a namespace
--filter-trait "name=value" Run tests with a matching trait
--filter-not-trait "name=value" Exclude tests with a matching trait

Multiple values can be specified with a single flag: --filter-class Foo Bar.

# .NET SDK 8/9
dotnet test -- --filter-class "MyNamespace.LoginTests"

# .NET SDK 10+
dotnet test --filter-class "MyNamespace.LoginTests"

# Combine: namespace + trait
dotnet test --filter-namespace "MyApp.Tests.Integration" --filter-trait "Category=Smoke"

xUnit v3 query filter language

For complex expressions, use --filter-query with a path-segment syntax:

/<assemblyFilter>/<namespaceFilter>/<classFilter>/<methodFilter>[traitName=traitValue]

Each segment matches against: assembly name, namespace, class name, method name. Use * for "match all" in any segment. Documentation: https://xunit.net/docs/query-filter-language

# xUnit.net v3 MTP — using query language (assembly/namespace/class/method[trait])
dotnet test -- --filter-query "/*/*/*IntegrationTests*/*[Category=Smoke]"

MTP filters — TUnit

TUnit uses --treenode-filter with a path-based syntax:

--treenode-filter "/<Assembly>/<Namespace>/<ClassName>/<TestName>"

Wildcards (*) are supported in any segment. Filter operators can be appended to test names for property-based filtering.

Operator Meaning
* Wildcard match
= Exact property match (e.g., [Category=Unit])
!= Exclude property value
& AND (combine conditions)
| OR (within a segment, requires parentheses)

Examples (TUnit):

# All tests in a class
dotnet run --treenode-filter "/*/*/LoginTests/*"

# A specific test
dotnet run --treenode-filter "/*/*/*/AcceptCookiesTest"

# By namespace prefix (wildcard)
dotnet run --treenode-filter "/*/MyProject.Tests.Api*/*/*"

# By custom property
dotnet run --treenode-filter "/*/*/*/*[Category=Smoke]"

# Exclude by property
dotnet run --treenode-filter "/*/*/*/*[Category!=Slow]"

# OR across classes
dotnet run --treenode-filter "/*/*/(LoginTests)|(SignupTests)/*"

# Combined: namespace + property
dot
よくある質問

フィルターとは何ですか?

テストランナーに、どのテストを含めるか、または飛ばすかを伝える短い式です。

すべてのフレームワークに対応していますか?

MSTest、NUnit、xUnit v3、TUnitに対応しています。構文はテストプラットフォームによって異なります。

テストを実行しますか?

いいえ。これは他のテストスキルが使う参考資料で、テストを自分で実行するツールではありません。

詳細

作者による元の説明

Reference-only filter syntax for VSTest and MTP with MSTest, NUnit, xUnit v3, and TUnit. Load only after the platform/framework is known and a consumer needs to create or translate a filter. Do not load for unfiltered runs or platform detection. Used by run-tests and mtp-hot-reload; never invoke directly.

repo: dotnet/skills

人気

GitHubのスター
5.8k
ランキング
#14628
ライセンス
MIT
更新日
2026/11/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル