首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打开NUnit.Framework -名称空间或模块未定义。F#中的参考

打开NUnit.Framework -名称空间或模块未定义。F#中的参考
EN

Stack Overflow用户
提问于 2015-02-11 11:44:19
回答 1查看 655关注 0票数 0

我用的是VS2013 ProfessionalF#C#Nunit。值得注意的是,这是我第一次尝试使用F#,所以问题很可能是愚蠢的,解决方案也是显而易见的。

我要做的是使用NUnit实现测试用例,并在TestCaseData中使用TestCaseSource属性。

测试:

代码语言:javascript
复制
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" ) ] 

功能测试:

代码语言:javascript
复制
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,运行良好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-11 12:40:39

我的问题很蠢。

.fs文件不能像C#文件那样添加到C#项目中。要正确地执行此操作,需要将F#项目添加到解决方案中,请参见下面的屏幕截图。

执行情况:

代码语言:javascript
复制
module Implementation

let Concat(text:string) = 
    "root"+ text

测试:

代码语言:javascript
复制
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

结果:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28453542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档