[英]open NUnit.Framework - the namespace or module is not defined. Referencing in F#
I am using VS2013 Professional
, F#
, C#
and Nunit
. 我正在使用VS2013 Professional
, F#
, C#
和Nunit
。 It is worth noting that this is my first attempt with F#
so question is most likely stupid and solution is obvious. 值得注意的是,这是我第一次尝试F#
因此问题很可能是愚蠢的,解决方案显而易见。
What I am trying to do is implement test cases using NUnit
and use TestCaseSource
attribute with TestCaseData
. 我想做的是使用NUnit
实现测试用例,并将TestCaseSource
属性与TestCaseData
。
Test: 测试:
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" ) ]
Function tested: 功能测试:
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]
One thing worth noting - I have created F#
test file and file with function by renaming .cs
file to .fs
. 值得注意的一件事-我通过将.cs
文件重命名为.fs
创建了F#
测试文件和具有功能的文件。
Problem: when I try to open
any library that is not System
(in this case Nuget package NUnit.Framework
and Referenced project Legal.Website.Infrastructure
) I get error: the namespace or module is not defined
both are referenced in Test Project and .cs
tests in same directory run fine. 问题:当我尝试open
任何非System
库时(在本例中为Nuget包NUnit.Framework
和所引用的项目Legal.Website.Infrastructure
),我收到错误消息: the namespace or module is not defined
都在Test Project和中被引用.cs
同一目录中的.cs
测试运行正常。
My question is stupid. 我的问题很愚蠢。
.fs
files cannot be added to C# project like for example .vb
files. .fs
文件不能像.vb
文件一样添加到C#项目中。 To do this properly one needs to add F# project to solution, see screenshot below. 要正确执行此操作,需要将F#项目添加到解决方案中,请参见下面的屏幕截图。
Implementation: 执行:
module Implementation
let Concat(text:string) =
"root"+ text
Test: 测试:
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
Debug -> Attach to process -> nunit-agent.exe 调试->附加到进程-> nunit-agent.exe
Result: 结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.