在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
问题似乎在于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);
现在我得到两个测试用例传递结果: