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

How to run fsharp test on Mac from terminal?

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

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

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

此答案 指示 运行 nunit-console 使用 .csproj.dll 文件。但是这些文件不存在于练习文件中。所以我不清楚该怎么做。

我已经使用自制软件安装了单声道。 我如何 运行 从 OSX 中的终端进行 NUnit 测试?

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

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

fsharpc HelloWorldTest.fs

mono nunit-console.exe HelloWorldTest.exe

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

我知道怎么做了:

1. 按照说明安装 dotnet https://www.microsoft.com/net/core#macos

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