简体   繁体   English

打开NUnit.Framework-未定义名称空间或模块。 在F#中引用

[英]open NUnit.Framework - the namespace or module is not defined. Referencing in F#

I am using VS2013 Professional , F# , C# and Nunit . 我正在使用VS2013 ProfessionalF#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.

相关问题 Mono和Specflow - `TestCaseAttribute&#39;在名称空间`NUnit.Framework&#39;中不存在 - Mono and Specflow - `TestCaseAttribute' does not exist in the namespace `NUnit.Framework' 在NUnit.Framework和Microsoft.VisualStudio.TestTools.UnitTesting命名空间中也发现了NUnit断言方法错误 - NUnit Assert method error as it is found in NUnit.Framework and Microsoft.VisualStudio.TestTools.UnitTesting namespace as well NUnit:无法加载程序集 nunit.framework - NUnit: Could not load assembly nunit.framework MonoGame 引用了不受支持的 nunit.framework 版本 - MonoGame references an unsupported version of nunit.framework 使用Xunit运行Specflow但是给出错误nunit.framework - Run Specflow with Xunit but gives error nunit.framework Specflow 2.3.2:为什么Specflow使用“ Microsoft.VisualStudio.TestTools”而不是“ NUnit.Framework”生成* .cs文件 - Specflow 2.3.2: why is Specflow generating *.cs files using “Microsoft.VisualStudio.TestTools” instead of “NUnit.Framework” 从同一解决方案打开 c# 命名空间,在 f# 中引用项目 - open c# namespace from same solution, referenced project in f# 在Android项目中引用F#代码 - Referencing F# code in android project 在F#模块中定义的两种类型,但只有一种在C#中可见 - Two types defined in an F# module but only one visible in C# F#认为我的类型未定义 - F# thinks my type is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM