How to run FsUnit tests on Linux / Mac
I have installed FsUnit
ยป nuget install fsunit
Attempting to resolve dependency 'NUnit (โฅ 2.6.3)'.
Installing 'NUnit 2.6.3'.
Successfully installed 'NUnit 2.6.3'.
Installing 'FsUnit 1.3.0.1'.
Successfully installed 'FsUnit 1.3.0.1'.
I created a simple unit test:
module Tests
open NUnit.Framework
open FsUnit
[<Test>]
let ``simple test`` () =
1 |> should equal 1
Here I am running my test:
ยป fsharpc -r NUnit.2.6.3/lib/nunit.framework.dll -r FsUnit.1.3.0.1/Lib/Net40/FsUnit.NUnit.dll 01_binomial_tests.fs
F# Compiler for F# 3.1 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
/Users/demas/development/book_exericses/fsharp_deep_dive/01_binomial_tests.fs(7,1): warning FS0988: Main module of program is empty: nothing will happen when it is run
It was linked, but I don't know how to run tests without VS
Update
I tried using NUnit.Runners
:
> nuget install NUnit.Runners
> fsharpc -r NUnit.2.6.3/lib/nunit.framework.dll -r FsUnit.1.3.0.1/Lib/Net40/FsUnit.NUnit.dll --target:library 01_binomial_tests.fs
> mono NUnit.Runners.2.6.4/tools/nunit-console.exe 01_binomial_tests.dll
NUnit-Console version 2.6.4.14350
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Unix 14.4.0.0
CLR Version: 2.0.50727.1433 ( Mono 3.5 ( 3.10.0 ((detached/92c4884 Thu Nov 13 23:27:38 EST 2014) ) )
ProcessModel: Default DomainUsage: Single
Execution Runtime: mono-3.5
Could not load file or assembly '01_binomial_tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
+3
source to share
1 answer
You have several options:
- Add dependency on
NUnit.Runners
NuGet package that comes with standalone runner - Use Xamarin Studio, which seems to have a Device Tests panel to run tests.
- Use FAKE , which is a good F # build tool that can run unit tests
I personally use FAKE because it automates everything beautifully. To do this, you need to add something like this to your FAKE build.fsx
script:
Target "Test" (fun _ ->
!! "/tests*.dll |> NUnit (fun p ->
{p with
DisableShadowCopy = true;
OutputFile = testDir + "TestResults.xml" })
)
You will need the dependencies on FAKE
and NUnit.Runners
and then FAKE should also find the runner automatically (so you don't need to explicitly specify it in your build script).
+4
source to share