With the dotnet test command in .NET Core, you can use a filter expression to run selected tests. This article demonstrates how to filter tests. The examples use dotnet test. If you're using vstest.console.exe, replace --filter with --testcasefilter:.
Syntax
.NET CLI
dotnettest --filter<Expression>
Expression is in the format <Property><Operator><Value>[|&<Expression>].
Expressions can be joined with boolean operators: | for boolean or, & for boolean and.
Expressions can be enclosed in parentheses. For example: (Name~MyClass) | (Name~MyClass2).
An expression without any operator is interpreted as a contains on the FullyQualifiedName property. For example, dotnet test --filter xyz is the same as dotnet test --filter FullyQualifiedName~xyz.
Property is an attribute of the Test Case. For example, the following properties are supported by popular unit test frameworks.
Test framework
Supported properties
MSTest
FullyQualifiedName Name ClassName Priority TestCategory
xUnit
FullyQualifiedName DisplayName Traits
Nunit
FullyQualifiedName Name Priority TestCategory
Operators
= exact match
!=not exact match
~ contains
!~ doesn't contain
Value is a string. All the lookups are case insensitive.
Character escaping
To use an exclamation mark (!) in a filter expression, you have to escape it in some Linux or macOS shells by putting a backslash in front of it (\!). For example, the following filter skips all tests in a namespace that contains IntegrationTests:
For Name or DisplayName, use the URL encoding for the special characters. For example, to run a test with the name MyTestMethod and a string value "text", use the following filter:
To run tests that have either FullyQualifiedName containing TestClass1and have a Trait with a key of "Category" and value of "CategoryA"or have a Trait with a key of "Priority" and value of 1.
Bạn có thể tìm thấy nguồn cho nội dung này trên GitHub, nơi bạn cũng có thể tạo và xem lại các vấn đề và yêu cầu kéo. Để biết thêm thông tin, hãy xem hướng dẫn dành cho người đóng góp của chúng tôi.
Ý kiến phản hồi về .NET
.NET là một dự án nguồn mở. Chọn liên kết để cung cấp ý kiến phản hồi:
Tham gia chuỗi buổi gặp gỡ để xây dựng các giải pháp AI có thể mở rộng dựa trên các trường hợp sử dụng trong thế giới thực với các nhà phát triển và chuyên gia đồng nghiệp.