I am trying to set up a very simple test F# project in linux with mono, using Forge to set up the project and install nuget packages. Forge creates a build.fsx
file which uses FAKE. I've tried to adjust this build file (in order to add tests) with inspiration from this tutorial http://fsharp.github.io/FAKE/gettingstarted.html. The tutorial, however, is using C# for testing and assumes Windows with .Net as environment. I want to use F# for testing and linux with mono as environment.
I think I almost got it working, but I am getting some cryptic error messages from NUnit. When running the build.fsx
file I get 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 [email protected] (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 looks like this
// 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 a file nunit-console.exe
under 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 with the name nunit-console.exe
.
My simple test file NUnit.Test.MyTests.fs
looks like following:
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 file test/NUnit.Test.MyTests.dll
seems to be generated just fine.
What does the cryptic error message mean, and how can I fix it so I can run my tests?
As mentioned by rmunn in the comment, I need to use the function NUnit3
because I am using NUnit version 3.4.1. The function resides in the FAKE.Testing
module http://fsharp.github.io/FAKE/apidocs/fake-testing-nunit3.html. I modified my build.fsx
file so it now looks like following:
// 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"
Note that you must specify ToolPath
all the way to the nunit3-console.exe
file, and not just the directory where it resides.
Now everything seems to work, and I get a fine and simple 'test-summary' in the console output when I run build.fsx
. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With