.net core+mstest单元测试

自定义多输入测试

	[DataTestMethod]
	[DataRow(-1)]
	[DataRow(0)]
	[DataRow(1)]
	public void ReturnFalseGivenValuesLessThan2(int value)
    {
        var result = _primeService.IsPrime(value);

        Assert.IsFalse(result, $"{value} should not be prime");
    }

dotnet test 相关指令

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTestNamespace
{
    [TestClass]
    public class UnitTest1
    {
        [TestCategory("CategoryA")]
        [Priority(1)]
        [TestMethod]
        public void TestMethod1()
        {
        }

        [Priority(2)]
        [TestMethod]
        public void TestMethod2()
        {
        }
    }
}
表达式结果
dotnet test --filter Method运行 FullyQualifiedName 包含 Method 的测试。 在 vstest 15.1+ 中可用。
dotnet test --filter Name~TestMethod1运行名称包含 TestMethod1 的测试。
dotnet test --filter ClassName=MSTestNamespace.UnitTest1运行属于类 MSTestNamespace.UnitTest1 的测试。注意: 由于 ClassName 值应有命名空间,因此 ClassName=UnitTest1 无效。
dotnet test --filter FullyQualifiedName!=MSTestNamespace.UnitTest1.TestMethod1运行除 MSTestNamespace.UnitTest1.TestMethod1 之外的其他所有测试。
dotnet test --filter TestCategory=CategoryA运行含 [TestCategory(“CategoryA”)] 批注的测试。
dotnet test --filter Priority=2运行含 [Priority(2)] 批注的测试。

使用条件运算符 | 和 &

表达式结果
dotnet test --filter “FullyQualifiedName~UnitTest1 or TestCategory=CategoryA”运行 FullyQualifiedName 包含 UnitTest1 或 TestCategory 是 CategoryA 的测试。
dotnet test --filter “FullyQualifiedName~UnitTest1&TestCategory=CategoryA”运行 FullyQualifiedName 包含 UnitTest1 且 TestCategory 是 CategoryA 的测试。
dotnet test --filter “(FullyQualifiedName~UnitTest1&TestCategory=CategoryA) or Priority=1”运行 FullyQualifiedName 包含 UnitTest1 且 TestCategory 是 CategoryA 或 Priority 是 1 的测试。

测试已发布的文件:

dotnet vstest out/MyProject.Tests.dll	
果你的应用以 netcoreapp 之外的框架为目标,则仍然可以通过使用框架标志传入目标框架来运行 dotnet vstest 命令。
dotnet vstest <MyPublishedTests>.dll --Framework:".NETFramework,Version=v4.6"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值