You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用FullyQualifiedName执行dotnet test时TestFixture参数化测试失败求助

解决带参数TestFixture的dotnet test筛选问题

针对你用[TestFixture(Platform.Android)]和[TestFixture(Platform.iOS)]标记的测试类,正确的筛选方式需要结合带参数的测试实例完全限定名,以下是具体方法:

方法一:使用FullyQualifiedName精确匹配

带参数的TestFixture会生成独立的测试实例,其完全限定名格式为命名空间.测试类名(参数值).测试方法名。

执行Android平台的SomeTest:

dotnet test --filter "FullyQualifiedName=TestNameSpace.TestClass(Platform.Android).SomeTest"

执行iOS平台的SomeTest:

dotnet test --filter "FullyQualifiedName=TestNameSpace.TestClass(Platform.iOS).SomeTest"

如果要执行某个平台下TestClass的所有测试方法,可使用模糊匹配(~):

# Android平台所有TestClass的测试
dotnet test --filter "FullyQualifiedName~TestNameSpace.TestClass(Platform.Android)"

方法二:添加Category属性批量筛选

如果需要更简洁的筛选方式,可以给TestFixture添加Category属性:

namespace TestNameSpace
{
    [TestFixture(Platform.Android), Category("Android")]
    [TestFixture(Platform.iOS), Category("iOS")]
    public class TestClass : YourBaseClass
    {
        public TestClass(Platform platform) : base(platform) {}
        
        [Test]
        public void SomeTest() {}
    }
}

之后直接通过Category筛选:

# 执行Android平台所有测试
dotnet test --filter "Category=Android"

# 执行iOS平台所有测试
dotnet test --filter "Category=iOS"

你之前的命令错误原因

  • 错误将Platform当成了命名空间的一部分,实际它是TestFixture的参数,需要放在类名后的括号中
  • 使用了不存在的筛选器cat,NUnit官方筛选器中没有该关键字
  • 错误尝试用TestCategory,但你的代码中并未给测试类/方法标记[TestCategory]属性

内容的提问来源于stack exchange,提问作者ViktorIp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 10:55:27