我试图在linux中用mono设置一个非常简单的testingF#项目,使用Forge来设置项目并安装nuget包。 Forge创build一个使用FAKE的build.fsx
文件。 我已经尝试从本教程http://fsharp.github.io/FAKE/gettingstarted.html中获得灵感来调整此构build文件(以添加testing) 。 不过,该教程正在使用C#进行testing,并假定Windows以.Net作为环境。 我想使用F#进行testing,并使用mono作为环境。
我想我几乎可以正常工作,但是我收到了一些来自NUnit的神秘错误信息。 运行build.fsx
文件时,最后出现以下错误:
... Invalid argument: -nologo The value '/home/michel/Documents/FSHARP/UnitTests/test/NUnit.Test.MyTests.dll' is not valid for option '--labels'. Invalid argument: -xml:./test/TestResults.xml Running build failed. Error: NUnit test failed (255). --------------------------------------------------------------------- Build Time Report --------------------------------------------------------------------- Target Duration ------ -------- Clean 00:00:00.0036366 Build 00:00:00.0402828 BuildTest 00:00:00.4911710 Total: 00:00:00.7494956 Status: Failure --------------------------------------------------------------------- 1) Fake.UnitTestCommon+FailedTestsException: NUnit test failed (255). at Fake.NUnitSequential.NUnit (Microsoft.FSharp.Core.FSharpFunc`2 setParams, IEnumerable`1 assemblies) <0x41d27e50 + 0x0039f> in <filename unknown>:0 at FSI_0001+clo@32-4.Invoke (Microsoft.FSharp.Core.Unit _arg4) <0x41d27dc0 + 0x0006f> in <filename unknown>:0 at Fake.TargetHelper+targetFromTemplate@195[a].Invoke (Microsoft.FSharp.Core.Unit unitVar0) <0x41cd59b0 + 0x00023> in <filename unknown>:0 at Fake.TargetHelper.runSingleTarget (Fake.TargetTemplate`1 target) <0x41ccb490 + 0x000ca> in <filename unknown>:0
我的build.fsx
文件看起来像这样
// include Fake libs #r "./packages/FAKE/tools/FakeLib.dll" open Fake // Directories let buildDir = "./build/" let testDir = "./test/" // version info let version = "0.1" // or retrieve from CI server // Targets Target "Clean" (fun _ -> CleanDirs [buildDir; testDir] ) Target "Build" (fun _ -> //MSBuildDebug buildDir "Build" appReferences !! "/UnitTesting/*.fsproj" |> MSBuildRelease buildDir "Build" |> Log "AppBuild-Output: " ) Target "BuildTest" (fun _ -> !! "src/NUnit.Test.MyTests/*.fsproj" |> MSBuildDebug testDir "Build" |> Log "TestBuild-Output: " ) Target "Test" (fun _ -> !! (testDir + "/NUnit.Test.MyTests.dll") |> NUnit (fun p -> { p with ToolPath = "packages/NUnit.ConsoleRunner/tools" //DisableShadowCopy = true; OutputFile = testDir + "TestResults.xml" }) ) Target "Default" (fun _ -> trace "HEEEELLOOOOOO world from FAKE!!!") "Clean" ==> "Build" ==> "BuildTest" ==> "Test" ==> "Default" RunTargetOrDefault "Default"
FAKE似乎正在查找packages/NUnit.ConsoleRunner/tools
目录下的文件nunit-console.exe
,但是没有这样的文件。 但是,有一个nunit3-console.exe
文件,所以我只是用名称nunit-console.exe
复制了这个文件。
我简单的testing文件NUnit.Test.MyTests.fs
如下所示:
namespace NUnit.Test.MyTests module testmodule = open NUnit.Framework let SayHello name = "Hello" [<TestFixture>] type myFixture() = [<Test>] member self.myTest() = Assert.AreEqual("Hello World!", SayHello "World")
和文件test/NUnit.Test.MyTests.dll
似乎生成就好了。
这个神秘的错误信息是什么意思,我该如何解决这个问题,以便我可以运行我的testing?
正如rmunn在评论中提到的,我需要使用NUnit3
函数,因为我使用的是NUnit版本3.4.1。 该函数驻留在FAKE.Testing
模块http://fsharp.github.io/FAKE/apidocs/fake-testing-nunit3.html中 。 我修改了我的build.fsx
文件,现在看起来如下所示:
// include Fake libs #r "./packages/FAKE/tools/FakeLib.dll" open Fake open Fake.Testing // NUnit3 is in here // Directories let buildDir = "./build/" let testDir = "./test/" // version info let version = "0.1" // or retrieve from CI server // Targets Target "Clean" (fun _ -> CleanDirs [buildDir; testDir] ) Target "Build" (fun _ -> !! "/UnitTesting/*.fsproj" |> MSBuildRelease buildDir "Build" |> Log "AppBuild-Output: " ) Target "BuildTest" (fun _ -> !! "src/NUnit.Test.MyTests/*.fsproj" |> MSBuildDebug testDir "Build" |> Log "TestBuild-Output: " ) Target "Test" (fun _ -> !! (testDir + "/NUnit.Test.*.dll") |> NUnit3 (fun p -> { p with ToolPath = "packages/NUnit.ConsoleRunner/tools/nunit3-console.exe" }) ) Target "Default" (fun _ -> trace "HEEEELLOOOOOO world from FAKE!!!") "Clean" ==> "Build" ==> "BuildTest" ==> "Test" ==> "Default" RunTargetOrDefault "Default"
请注意,您必须一直指定到nunit3-console.exe
文件的nunit3-console.exe
,而不仅仅是它所在的目录。
现在一切似乎都奏效了,当我运行build.fsx
时,在控制台输出中我得到了一个很好的,简单的“test-summary”。 🙂