如何在终端上运行Mac上的fsharp测试?

时间:2016-10-05 07:25:20

标签: macos f# mono nunit

我想学习fsharp。所以我在看exercism.io

在他们的自述文件中,他们指示使用Xamarin Studio来运行测试 http://exercism.io/languages/fsharp/tests

但我想从终端运行测试。来自练习的练习仅包括一个F#文件,例如HelloWorldTest.fs

此回答Running tests on Mac OS X console using mono/nunit-console/4指示使用nunit-console.csproj文件运行.dll。但这些文件不存在于练习文件中。所以我不清楚该怎么做。

我使用自制软件安装mono。 如何在OSX中从终端运行NUnit测试?

2 个答案:

答案 0 :(得分:0)

您可能必须在命令行上使用xbuild来编译fsproj文件,然后在命令行上也可以使用nunit执行生成的dll。

如果你没有fsproj,你可以直接在文件上使用fsharpc然后调用nunit,记住使用mono来执行nunit。

fsharpc HelloWorldTest.fs

mono nunit-console.exe HelloWorldTest.exe

很抱歉,我无法对此进行测试,但应该是这样的。

答案 1 :(得分:0)

我想出了如何做到这一点:

1。按照https://www.microsoft.com/net/core#macos

所述安装dotnet

2. 在练习运行的文件夹中

dotnet new --lang f#

3。Program.fs重命名为演习名称,例如HelloWorld.fs

4. project.json更改为

{
  "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"
}

这包括nunit依赖项。

注意includeFiles,这应该包括练习的源代码文件和测试文件。例如HelloWorld.fsHelloWorldTest.fs

5. 通过执行

安装所需的软件包
dotnet restore

6. :将您的代码添加到之前重命名的源文件,例如HelloWorld.fs

7。最后,通过执行

运行测试
 dotnet test
相关问题