F# 运行 NUnit 测试
F# Running NUnit Tests
我只想 运行 一些单元测试,我已将它们添加到 .fs 文件中。我想在我想要 运行 时从应用程序入口点调用它们。
这是我写的测试
namespace InvoiceApp
open System
open NUnit.Framework
open FsUnit
module Test =
let testPassed testName = printfn "Test Passed!! - %s" testName
let testFailed testName = printfn "Test Failed!! - %s" testName
[<TestFixture>]
type Test() =
[<TestCase(200,10,20)>]
let ``When profitmarging is 10% and total is 200 expect 20 `` x y z () =
try
Math.percentage x y |> should equal z
testPassed "When profitmarging is 10% and total is 200 expect 20"
with
| :? NUnit.Framework.AssertionException as ex ->
testFailed "When profitmarging is 10% and total is 200 expect 20"
printfn "%s" ex.Message
如何从不同 .fs 文件的入口点调用这些测试?
看看 SimpleTestRunner
和 RemoteTestRunner
,ala this question。
不久前我构建了一个 NUnit 测试运行器作为 F# 模块,它应该支持您在命令行应用程序场景中的简单执行,请参阅 Running TAP。
要设置它,只需包含此 F# snippet 并调用测试:
Tap.Run typeof<InvoiceApp.Test>
注意:您还需要将测试用例更改为成员函数,并为 NUnit 的内置运行器或 TAP 运行器使用非通用元组参数才能看到它,即
member test.``When profitmarging is 10% and total is 200 expect 20 `` (x:int,y:int,z:int) =
我只想 运行 一些单元测试,我已将它们添加到 .fs 文件中。我想在我想要 运行 时从应用程序入口点调用它们。
这是我写的测试
namespace InvoiceApp
open System
open NUnit.Framework
open FsUnit
module Test =
let testPassed testName = printfn "Test Passed!! - %s" testName
let testFailed testName = printfn "Test Failed!! - %s" testName
[<TestFixture>]
type Test() =
[<TestCase(200,10,20)>]
let ``When profitmarging is 10% and total is 200 expect 20 `` x y z () =
try
Math.percentage x y |> should equal z
testPassed "When profitmarging is 10% and total is 200 expect 20"
with
| :? NUnit.Framework.AssertionException as ex ->
testFailed "When profitmarging is 10% and total is 200 expect 20"
printfn "%s" ex.Message
如何从不同 .fs 文件的入口点调用这些测试?
看看 SimpleTestRunner
和 RemoteTestRunner
,ala this question。
不久前我构建了一个 NUnit 测试运行器作为 F# 模块,它应该支持您在命令行应用程序场景中的简单执行,请参阅 Running TAP。
要设置它,只需包含此 F# snippet 并调用测试:
Tap.Run typeof<InvoiceApp.Test>
注意:您还需要将测试用例更改为成员函数,并为 NUnit 的内置运行器或 TAP 运行器使用非通用元组参数才能看到它,即
member test.``When profitmarging is 10% and total is 200 expect 20 `` (x:int,y:int,z:int) =