如何在Mac终端上运行F#测试?

6

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

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

但是,我希望能够直接从终端运行测试。exercism的练习只包括一个F#文件,例如HelloWorldTest.fs

这个答案Running tests on Mac OS X console using mono/nunit-console/4指示使用.csproj.dll文件运行nunit-console。 但是这些文件在exercism文件中不存在。 我不清楚该怎么做。

我已经使用homebrew安装了mono。如何在OSX终端中运行NUnit测试?


1
很遗憾,该答案似乎缺少步骤或不适用于这种特定情况。 - Sebastian
2个回答

2
你可能需要在命令行上使用xbuild编译fsproj文件,然后使用nunit在命令行上执行生成的dll。如果你没有fsproj,可以直接对文件使用fsharpc,然后调用nunit,记得使用mono来执行nunit。 fsharpc HelloWorldTest.fs mono nunit-console.exe HelloWorldTest.exe 很抱歉我不能测试这个,但应该是这样的。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接