6

I want to learn fsharp. So I'm looking at exercism.io

In their readme they instruct to use Xamarin Studio for running the test http://exercism.io/languages/fsharp/tests

But I would like to just run the tests from the terminal. The exercises from exercism only include one F# file e.g. HelloWorldTest.fs.

This answer Running tests on Mac OS X console using mono/nunit-console/4 instructs to run nunit-console with a .csproj or .dll file. But these files are not present in the exercism files. So I'm not clear what to do.

I have install mono using homebrew. How do I run the NUnit test from the terminal in OSX?

Community
  • 1
  • 1
Sebastian
  • 2,249
  • 17
  • 20
  • Possible duplicate of [Running tests on Mac OS X console using mono/nunit-console/4](http://stackoverflow.com/questions/33828340/running-tests-on-mac-os-x-console-using-mono-nunit-console-4) – Honza Brestan Oct 05 '16 at 09:18
  • 1
    Unfortunately that answer seems to be missing steps or doesn't apply to this particular case. – Sebastian Oct 05 '16 at 22:56

2 Answers2

2

You may have to use xbuild on the command line to compile the fsproj file then the resulting dll can be executed with nunit on the commandline also.

If you don't have the fsproj you can use fsharpc on the file directly then call nunit, remembering to use mono to execute nunit.

fsharpc HelloWorldTest.fs

mono nunit-console.exe HelloWorldTest.exe

Sorry am not in a position to test this, but should be something like this.

Mr. Mr.
  • 4,257
  • 3
  • 27
  • 42
0

I figured out how to do this:

1. install dotnet as described https://www.microsoft.com/net/core#macos

2. In the folder of the exercise run

dotnet new --lang f#

3. Rename Program.fs to the name of the exercise e.g. HelloWorld.fs

4. Change project.json to

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "compilerName": "fsc",
    "compile": {
      "includeFiles": [
        "HelloWorld.fs",
        "HelloWorldTest.fs"
      ]
    }
  },
  "dependencies": {
    "NUnit": "3.4.1",
    "dotnet-test-nunit": "3.4.0-beta-2"
  },
  "tools": {
    "dotnet-compile-fsc": "1.0.0-preview2-*"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "portable-net45+win8",
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.1"
        },
        "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-160629"
      }
    }
  },
  "testRunner": "nunit"
}

This includes the nunit dependency.

Note includeFiles, this should include the source code file for the exercise and the test file. e.g. HelloWorld.fs and HelloWorldTest.fs

5. Install required packages by doing

dotnet restore

6. Add your code to the previously renamed source file e.g. HelloWorld.fs

7. Finallly, run test by doing

 dotnet test
Sebastian
  • 2,249
  • 17
  • 20