我用的是VS2013 Professional,F#,C#和Nunit。值得注意的是,这是我第一次尝试使用F#,所以问题很可能是愚蠢的,解决方案也是显而易见的。
我要做的是使用NUnit实现测试用例,并在TestCaseData中使用TestCaseSource属性。
测试:
namespace Legal.Tests.Helpers
open System
open System.Collections.Generic
open System.Linq
open System.Text
open System.Threading.Tasks
open NUnit.Framework
open Legal.Website.Infrastructure
type FTest() =
[<TestFixture>]
[<TestCaseSource("FTestData")>]
let ConcatTest(text : string, expected : string) =
[<Test>]
let actual = Saga.Services.Legal.Website.Infrastructure.FunctionModule.TestFunction text
Assert.AreEqual expected actual
let FTestData : seq<TestCaseData> = [ new TestCaseData (text = "x", expected = "Item1xItem2" ); new TestCaseData (text = "y", expected = "Item1yItem2" ) ] 功能测试:
namespace Legal.Website.Infrastructure
open System
open System.Collections.Generic
open System.Linq
open System.Web
type Test(text2 : string) =
member this.Text = "Item1"
member this.Text2 = text2
module functions =
let TestFunction (text : string) =
let test = new Test (text2 = "Item2")
String.Concat [test.Text; text; test.Text2]值得注意的是-我通过将F#文件重命名为.fs创建了带有函数的.cs测试文件和文件。
问题:当我尝试任何不是System的库(在本例中是NugetPackageNUnit.Framework和ReferencedProjectLegal.Website.Infrastructure)时,我得到了错误:在Test和.cs测试中,在同一个目录中都引用了the namespace or module is not defined,运行良好。
发布于 2015-02-11 12:40:39
我的问题很蠢。
.fs文件不能像C#文件那样添加到C#项目中。要正确地执行此操作,需要将F#项目添加到解决方案中,请参见下面的屏幕截图。

执行情况:
module Implementation
let Concat(text:string) =
"root"+ text测试:
module Test
open NUnit.Framework
[<TestFixture>]
type Test() =
member this.ConcatinationTestData() =
[new TestCaseData("roottext","text"); new TestCaseData("root","")]
[<Test>]
[<TestCaseSource("ConcatinationTestData")>]
static member ConcatinationTest(expected:string, text:string) =
Assert.AreEqual(expected,Implementation.Concat(text))
|> ignore调试->附加到进程-> nunit-agent.exe
结果:

https://stackoverflow.com/questions/28453542
复制相似问题