linux 中的 F# 单元测试项目与单声道(FAKE,NUnit 3)
F# unit test projects in linux with mono (FAKE, NUnit 3)
我正在尝试使用 Forge to set up the project and install nuget packages. Forge creates a build.fsx
file which uses FAKE. I've tried to adjust this build file (in order to add tests) with inspiration from this tutorial http://fsharp.github.io/FAKE/gettingstarted.html 在 linux 中使用单声道设置一个非常简单的测试 F# 项目。然而,本教程使用 C# 进行测试,并假设 Windows 以 .Net 作为环境。我想使用 F# 进行测试,linux 使用单声道作为环境。
我想我几乎可以正常工作了,但是我从 NUnit 收到了一些神秘的错误消息。当 运行 连接 build.fsx
文件时,我在最后得到以下错误:
...
Invalid argument: -nologo
The value '/home/michel/Documents/FSHARP/UnitTests/test/NUnit.Test.MyTests.dll' is not valid for option '--labels'.
Invalid argument: -xml:./test/TestResults.xml
Running build failed.
Error:
NUnit test failed (255).
---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target Duration
------ --------
Clean 00:00:00.0036366
Build 00:00:00.0402828
BuildTest 00:00:00.4911710
Total: 00:00:00.7494956
Status: Failure
---------------------------------------------------------------------
1) Fake.UnitTestCommon+FailedTestsException: NUnit test failed (255).
at Fake.NUnitSequential.NUnit (Microsoft.FSharp.Core.FSharpFunc`2 setParams, IEnumerable`1 assemblies) <0x41d27e50 + 0x0039f> in <filename unknown>:0
at FSI_0001+clo@32-4.Invoke (Microsoft.FSharp.Core.Unit _arg4) <0x41d27dc0 + 0x0006f> in <filename unknown>:0
at Fake.TargetHelper+targetFromTemplate@195[a].Invoke (Microsoft.FSharp.Core.Unit unitVar0) <0x41cd59b0 + 0x00023> in <filename unknown>:0
at Fake.TargetHelper.runSingleTarget (Fake.TargetTemplate`1 target) <0x41ccb490 + 0x000ca> in <filename unknown>:0
我的 build.fsx
文件看起来像这样
// include Fake libs
#r "./packages/FAKE/tools/FakeLib.dll"
open Fake
// Directories
let buildDir = "./build/"
let testDir = "./test/"
// version info
let version = "0.1" // or retrieve from CI server
// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir]
)
Target "Build" (fun _ ->
//MSBuildDebug buildDir "Build" appReferences
!! "/UnitTesting/*.fsproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)
Target "BuildTest" (fun _ ->
!! "src/NUnit.Test.MyTests/*.fsproj"
|> MSBuildDebug testDir "Build"
|> Log "TestBuild-Output: "
)
Target "Test" (fun _ ->
!! (testDir + "/NUnit.Test.MyTests.dll")
|> NUnit (fun p ->
{ p with
ToolPath = "packages/NUnit.ConsoleRunner/tools"
//DisableShadowCopy = true;
OutputFile = testDir + "TestResults.xml" })
)
Target "Default" (fun _ -> trace "HEEEELLOOOOOO world from FAKE!!!")
"Clean" ==> "Build" ==> "BuildTest" ==> "Test" ==> "Default"
RunTargetOrDefault "Default"
FAKE好像在packages/NUnit.ConsoleRunner/tools
目录下找文件nunit-console.exe
,但是没有这个文件。但是,有一个 nunit3-console.exe
文件,所以我只复制了一个名为 nunit-console.exe
.
的文件
我的简单测试文件 NUnit.Test.MyTests.fs
如下所示:
namespace NUnit.Test.MyTests
module testmodule =
open NUnit.Framework
let SayHello name = "Hello"
[<TestFixture>]
type myFixture() =
[<Test>]
member self.myTest() =
Assert.AreEqual("Hello World!", SayHello "World")
并且文件 test/NUnit.Test.MyTests.dll
似乎生成得很好。
神秘的错误消息是什么意思,我该如何修复它以便我可以 运行 我的测试?
正如 rmunn 在评论中提到的,我需要使用函数 NUnit3
因为我使用的是 NUnit 3.4.1 版。该函数驻留在 FAKE.Testing
模块 http://fsharp.github.io/FAKE/apidocs/fake-testing-nunit3.html 中。我修改了我的 build.fsx
文件,现在它看起来像下面这样:
// include Fake libs
#r "./packages/FAKE/tools/FakeLib.dll"
open Fake
open Fake.Testing // NUnit3 is in here
// Directories
let buildDir = "./build/"
let testDir = "./test/"
// version info
let version = "0.1" // or retrieve from CI server
// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir]
)
Target "Build" (fun _ ->
!! "/UnitTesting/*.fsproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)
Target "BuildTest" (fun _ ->
!! "src/NUnit.Test.MyTests/*.fsproj"
|> MSBuildDebug testDir "Build"
|> Log "TestBuild-Output: "
)
Target "Test" (fun _ ->
!! (testDir + "/NUnit.Test.*.dll")
|> NUnit3 (fun p ->
{ p with
ToolPath = "packages/NUnit.ConsoleRunner/tools/nunit3-console.exe" })
)
Target "Default" (fun _ -> trace "HEEEELLOOOOOO world from FAKE!!!")
"Clean" ==> "Build" ==> "BuildTest" ==> "Test" ==> "Default"
RunTargetOrDefault "Default"
请注意,您必须指定 ToolPath
一直到 nunit3-console.exe
文件,而不仅仅是它所在的目录。
现在一切似乎都正常了,当我 运行 build.fsx
时,我在控制台输出中得到了一个简单明了的 'test-summary'。 :)
我正在尝试使用 Forge to set up the project and install nuget packages. Forge creates a build.fsx
file which uses FAKE. I've tried to adjust this build file (in order to add tests) with inspiration from this tutorial http://fsharp.github.io/FAKE/gettingstarted.html 在 linux 中使用单声道设置一个非常简单的测试 F# 项目。然而,本教程使用 C# 进行测试,并假设 Windows 以 .Net 作为环境。我想使用 F# 进行测试,linux 使用单声道作为环境。
我想我几乎可以正常工作了,但是我从 NUnit 收到了一些神秘的错误消息。当 运行 连接 build.fsx
文件时,我在最后得到以下错误:
...
Invalid argument: -nologo
The value '/home/michel/Documents/FSHARP/UnitTests/test/NUnit.Test.MyTests.dll' is not valid for option '--labels'.
Invalid argument: -xml:./test/TestResults.xml
Running build failed.
Error:
NUnit test failed (255).
---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target Duration
------ --------
Clean 00:00:00.0036366
Build 00:00:00.0402828
BuildTest 00:00:00.4911710
Total: 00:00:00.7494956
Status: Failure
---------------------------------------------------------------------
1) Fake.UnitTestCommon+FailedTestsException: NUnit test failed (255).
at Fake.NUnitSequential.NUnit (Microsoft.FSharp.Core.FSharpFunc`2 setParams, IEnumerable`1 assemblies) <0x41d27e50 + 0x0039f> in <filename unknown>:0
at FSI_0001+clo@32-4.Invoke (Microsoft.FSharp.Core.Unit _arg4) <0x41d27dc0 + 0x0006f> in <filename unknown>:0
at Fake.TargetHelper+targetFromTemplate@195[a].Invoke (Microsoft.FSharp.Core.Unit unitVar0) <0x41cd59b0 + 0x00023> in <filename unknown>:0
at Fake.TargetHelper.runSingleTarget (Fake.TargetTemplate`1 target) <0x41ccb490 + 0x000ca> in <filename unknown>:0
我的 build.fsx
文件看起来像这样
// include Fake libs
#r "./packages/FAKE/tools/FakeLib.dll"
open Fake
// Directories
let buildDir = "./build/"
let testDir = "./test/"
// version info
let version = "0.1" // or retrieve from CI server
// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir]
)
Target "Build" (fun _ ->
//MSBuildDebug buildDir "Build" appReferences
!! "/UnitTesting/*.fsproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)
Target "BuildTest" (fun _ ->
!! "src/NUnit.Test.MyTests/*.fsproj"
|> MSBuildDebug testDir "Build"
|> Log "TestBuild-Output: "
)
Target "Test" (fun _ ->
!! (testDir + "/NUnit.Test.MyTests.dll")
|> NUnit (fun p ->
{ p with
ToolPath = "packages/NUnit.ConsoleRunner/tools"
//DisableShadowCopy = true;
OutputFile = testDir + "TestResults.xml" })
)
Target "Default" (fun _ -> trace "HEEEELLOOOOOO world from FAKE!!!")
"Clean" ==> "Build" ==> "BuildTest" ==> "Test" ==> "Default"
RunTargetOrDefault "Default"
FAKE好像在packages/NUnit.ConsoleRunner/tools
目录下找文件nunit-console.exe
,但是没有这个文件。但是,有一个 nunit3-console.exe
文件,所以我只复制了一个名为 nunit-console.exe
.
我的简单测试文件 NUnit.Test.MyTests.fs
如下所示:
namespace NUnit.Test.MyTests
module testmodule =
open NUnit.Framework
let SayHello name = "Hello"
[<TestFixture>]
type myFixture() =
[<Test>]
member self.myTest() =
Assert.AreEqual("Hello World!", SayHello "World")
并且文件 test/NUnit.Test.MyTests.dll
似乎生成得很好。
神秘的错误消息是什么意思,我该如何修复它以便我可以 运行 我的测试?
正如 rmunn 在评论中提到的,我需要使用函数 NUnit3
因为我使用的是 NUnit 3.4.1 版。该函数驻留在 FAKE.Testing
模块 http://fsharp.github.io/FAKE/apidocs/fake-testing-nunit3.html 中。我修改了我的 build.fsx
文件,现在它看起来像下面这样:
// include Fake libs
#r "./packages/FAKE/tools/FakeLib.dll"
open Fake
open Fake.Testing // NUnit3 is in here
// Directories
let buildDir = "./build/"
let testDir = "./test/"
// version info
let version = "0.1" // or retrieve from CI server
// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir]
)
Target "Build" (fun _ ->
!! "/UnitTesting/*.fsproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)
Target "BuildTest" (fun _ ->
!! "src/NUnit.Test.MyTests/*.fsproj"
|> MSBuildDebug testDir "Build"
|> Log "TestBuild-Output: "
)
Target "Test" (fun _ ->
!! (testDir + "/NUnit.Test.*.dll")
|> NUnit3 (fun p ->
{ p with
ToolPath = "packages/NUnit.ConsoleRunner/tools/nunit3-console.exe" })
)
Target "Default" (fun _ -> trace "HEEEELLOOOOOO world from FAKE!!!")
"Clean" ==> "Build" ==> "BuildTest" ==> "Test" ==> "Default"
RunTargetOrDefault "Default"
请注意,您必须指定 ToolPath
一直到 nunit3-console.exe
文件,而不仅仅是它所在的目录。
现在一切似乎都正常了,当我 运行 build.fsx
时,我在控制台输出中得到了一个简单明了的 'test-summary'。 :)