f#单元测试中是否有DataRowAttribute?

问题描述 投票:3回答:1

在C#中,我可以这样做(DataRowAttribute (c#)

[TestMethod]
[DataRow(1,2,3)]
[DataRow(2,2,4)]
public void TestSum (int x, int y, int expected)

我找不到在f#中执行此操作的方法。如果不存在,如何为f#单元测试创​​建此类属性?


更新

在Jonathon Chase的[<DataRow (2,4,6)>]建议下提供代码。不幸的是,测试运行程序未发现测试AddTest

namespace FsharpTests

open System
open Microsoft.VisualStudio.TestTools.UnitTesting

[<TestClass>]
type TestClass () =

    [<TestMethod>]
    member this.TestMethodPassing() =
        Assert.IsTrue(true);

    [<TestMethod>]
    [<DataRow (1,2,3)>]
    [<DataRow (2,4,6)>]
     member this.AddTest(a, b, expected) = 
        Assert.AreEqual(expected, a+b); //won't be discovered by the test runner
c# f#
1个回答
0
投票

问题似乎在于typing参数。

当我将您的测试调整为以下测试时,[[确实有效(不是键入的参数):

namespace UnitTestProject1 open Microsoft.VisualStudio.TestTools.UnitTesting [<TestClass>] type TestClass () = [<TestMethod>] [<DataRow (1,2,3)>] [<DataRow (2,4,6)>] member this.AddTest (a:int, b:int, expected:int) = Assert.AreEqual(expected, a+b);
现在我得到两个测试用例传递结果:enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.