F# 无法使用多参数构造函数从 TestFixtureSource 和 class 创建 NUnit 测试
F# unable to create NUnit tests from TestFixtureSource and class with multiple parameter constructor
我是 F# 的新手,我想知道是否有可能(未使用 NUnit)在其构造函数中构造一个测试 class 多个参数,并具有一些类似的构造 - 下面以
信息:
OneTimeSetUp: 没有找到合适的构造函数
// if data with one parameter, no problem to run the tests
// the data not only the constants at the compile time, so need to work TestFixtureSoource attribute.
type SimpleFixtureArgs =
static member Source = [| (String.Empty, String.Empty); ("hello", "hello") |]
[<TestFixtureSource(typeof<SimpleFixtureArgs>, "Source")>]
type ``simple tests class``(text, text2) =
[<Test>]
member this.``simple test``() =
let expexted = text
let actual = text2
Assert.AreEqual(expexted, actual)
自从删除一个参数(例如 text2)并拥有适当的一个参数 TestFixtureSource 后,它开始工作...
所以问题是如何编写 NUnit 测试以使用具有多个参数的 TestFixtureSource?
TIA,
莫伊米尔
文本夹具源的各个项目应该是对象数组或派生自 TestFixtureParameters class (NUnit documentation)。但是元组不是对象数组——它是单个对象。因此,将数组的源 属性 更改为 return IEnumerbale
(或数组):
type SimpleFixtureArgs =
static member Source = seq {
[| String.Empty; String.Empty|]
[| "hello"; "hello"|]
}
后来需要处理不同类型的参数。
F# 中的代码对之前的答案稍作修改,对我有用。
type SimpleFixtureArgs2 =
static member Source : seq<obj []> =
seq {
yield [| String.Empty; String.Empty; 1; 1 |]
yield [| "hello"; "hello"; 2; 2 |]
}
[<TestFixtureSource(typeof<SimpleFixtureArgs2>, "Source")>]
type ``simple tests2 class``(text1, text2, num1, num2) =
[<Test>]
member this.``simple strings and integers test``() =
let expextedText = text1
let actualText = text2
Assert.AreEqual(expextedText, actualText)
Assert.AreEqual(num1, num2)
我是 F# 的新手,我想知道是否有可能(未使用 NUnit)在其构造函数中构造一个测试 class 多个参数,并具有一些类似的构造 - 下面以 信息: OneTimeSetUp: 没有找到合适的构造函数
// if data with one parameter, no problem to run the tests
// the data not only the constants at the compile time, so need to work TestFixtureSoource attribute.
type SimpleFixtureArgs =
static member Source = [| (String.Empty, String.Empty); ("hello", "hello") |]
[<TestFixtureSource(typeof<SimpleFixtureArgs>, "Source")>]
type ``simple tests class``(text, text2) =
[<Test>]
member this.``simple test``() =
let expexted = text
let actual = text2
Assert.AreEqual(expexted, actual)
自从删除一个参数(例如 text2)并拥有适当的一个参数 TestFixtureSource 后,它开始工作...
所以问题是如何编写 NUnit 测试以使用具有多个参数的 TestFixtureSource?
TIA, 莫伊米尔
文本夹具源的各个项目应该是对象数组或派生自 TestFixtureParameters class (NUnit documentation)。但是元组不是对象数组——它是单个对象。因此,将数组的源 属性 更改为 return IEnumerbale
(或数组):
type SimpleFixtureArgs =
static member Source = seq {
[| String.Empty; String.Empty|]
[| "hello"; "hello"|]
}
后来需要处理不同类型的参数。 F# 中的代码对之前的答案稍作修改,对我有用。
type SimpleFixtureArgs2 =
static member Source : seq<obj []> =
seq {
yield [| String.Empty; String.Empty; 1; 1 |]
yield [| "hello"; "hello"; 2; 2 |]
}
[<TestFixtureSource(typeof<SimpleFixtureArgs2>, "Source")>]
type ``simple tests2 class``(text1, text2, num1, num2) =
[<Test>]
member this.``simple strings and integers test``() =
let expextedText = text1
let actualText = text2
Assert.AreEqual(expextedText, actualText)
Assert.AreEqual(num1, num2)