Langsung ke konten
Skillpedia
Testing5.8k · #14628

filter-syntax

Fungsinya

Referensi ini menjelaskan cara menulis filter pengujian yang memilih pengujian .NET mana yang berjalan, untuk framework yang umum. Referensi ini untuk pengembang yang ingin menjalankan sebagian pengujiannya saja.

Kapan dipakai

  • ✓Saat Anda ingin menjalankan sebagian pengujian .NET saja, misalnya satu kelas atau satu kategori.
  • ✓Saat Anda perlu mengecualikan pengujian yang lambat atau integrasi dari sebuah run.
  • ✓Saat Anda perlu menerjemahkan filter dari sintaks VSTest ke sintaks Microsoft.Testing.Platform.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/filter-syntax/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Bagaimana cara menjalankan hanya pengujian integrasi di proyek MSTest saya dan melewati yang lambat?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent menentukan platform dan framework pengujian, lalu menulis filter dengan nama properti dan operator yang tepat, seperti contains atau not equal.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum

Apa itu filter?

Filter adalah ekspresi singkat yang memberi tahu runner pengujian mana yang disertakan atau dilewati.

Apakah ini berlaku untuk setiap framework?

Skill ini mencakup MSTest, NUnit, xUnit v3, dan TUnit, dan sintaksnya bergantung pada platform pengujian.

Apakah referensi ini menjalankan pengujian?

Tidak. Ini adalah referensi yang dipakai skill pengujian lain, bukan alat yang menjalankan pengujian sendiri.

Detail

Deskripsi asli dari pembuat

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

Popularitas

Bintang GitHub
5.8k
Peringkat
#14628
Lisensi
MIT
Diperbarui
2/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa