在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
问题似乎在于键入参数。
当我将测试调整为以下各项时,它确实起作用(而不是键入的参数):
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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句