0
我正在使用VS2013 Professional
,F#
, C#
和Nunit
。值得注意的是,这是我第一次尝试F#
,所以问题很可能很愚蠢,解决方案很明显。open NUnit.Framework - 命名空间或模块未定义。在F#中引用
我想要做的是使用NUnit
实现测试用例,并使用TestCaseSource
属性与TestCaseData
。
测试:
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#
测试文件,并通过重命名.cs
文件.fs
与功能文件。
问题:当我尝试open
不是System
任何库(在这种情况下NuGet包NUnit.Framework
和引用的项目Legal.Website.Infrastructure
)我得到错误:在同一个目录下运行良好the namespace or module is not defined
都在测试项目中引用和.cs
测试。
不知道我的理解,但 - 我不认为你可以重命名'.cs'文件到'.fs'文件 - 你需要为此创建一个新的F#项目。 – 2015-02-11 12:33:02
@TomasPetricek所以我不能在C#项目中使用.fs文件,例如.vb文件。 – 2015-02-11 12:35:08
@TomasPetricek你可以请你的评论作为答案,所以我可以接受它。谢谢。 – 2015-02-12 12:22:38