F # unit test projects in linux with mono (FAKE, NUnit 3)

I am trying to set up a very simple F # test project on linux with mono using Forge to set up a project and install nuget packages. Forge creates a build.fsx file that FAKE uses. I tried to customize this build file (to add tests) with inspiration from this tutorial http://fsharp.imtqy.com/FAKE/gettingstarted.html . However, the tutorial uses C # for testing and assumes Windows with .Net as an environment. I want to use F # for testing and linux with mono as an environment.

I think almost everything works for me, but from NUnit I get some cryptic error messages. When I run the build.fsx file build.fsx I get the following errors at the end:

 ... 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 

My build.fsx file is as follows

 // 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 seems to be looking for the nunit-console.exe file in the packages/NUnit.ConsoleRunner/tools directory, but there is no such file. However, there is a nunit3-console.exe file, so I just made a copy of this file called nunit-console.exe .

My simple test file NUnit.Test.MyTests.fs looks like this:

 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") 

and the test/NUnit.Test.MyTests.dll seems to be generated just fine.

What does a critical error message mean, and how can I fix it so that I can run my tests?

+5
source share
1 answer

As mentioned in the rmunn comment, I need to use the NUnit3 function because I am using NUnit version 3.4.1. The function is in the FAKE.Testing module http://fsharp.imtqy.com/FAKE/apidocs/fake-testing-nunit3.html . I modified the build.fsx file, so now it looks like this:

 // 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" 

Please note that you must specify ToolPath entire path to the nunit3-console.exe file, and not just the directory in which it is located.

Now everything works, and I get a wonderful and simple "test summary" on the console output when I run build.fsx . :)

+7
source

All Articles