在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
答案 0 :(得分:0)
问题似乎在于键入参数。
当我将测试调整为以下内容时,它起作用(不是类型化的参数):
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);