如何在Linux / Mac上启动FsUnit测试

时间:2015-06-09 15:09:58

标签: f#

我已经安装了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'.

我创建了简单的单元测试:

module Tests

open NUnit.Framework
open FsUnit

[<Test>]
let ``simple test`` () =
  1 |> should equal 1

我正在启动我的测试:

» 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

编译得很好,但我不知道如何在没有VS

的情况下启动测试

更新

我尝试使用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.

1 个答案:

答案 0 :(得分:4)

您有几个选择:

  • 添加对NUnit.Runners NuGet程序包的依赖,该程序包附带一个独立的运行程序
  • 使用Xamarin Studio,它似乎有Unit Tests panel来运行测试
  • 使用FAKE这是一个可以运行单元测试的不错的F#构建工具

我个人使用FAKE,因为它可以很好地自动化所有内容。为此,您需要在您的FAKE build.fsx脚本中添加类似的内容:

Target "Test" (fun _ ->
    !! "/tests*.dll |> NUnit (fun p ->
        {p with
           DisableShadowCopy = true;
           OutputFile = testDir + "TestResults.xml" })
)

您需要依赖FAKENUnit.Runners,然后FAKE也应该自动找到转轮(因此您不必在构建脚本中明确设置它)。