我希望运行一些单元测试,我已将它们添加到.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文件的入口点调用这些测试?
答案 0 :(得分:2)
不久前,我构建了一个NUnit测试运行器作为F#模块,它应该支持您在命令行应用场景中的简单执行,请参阅Running TAP。
要设置它,只需包含此F# snippet并使用以下命令调用测试:
Tap.Run typeof<InvoiceApp.Test>
注意:您还需要将测试用例更改为成员函数,并为NUnit的内置运行器或TAP运行器使用非通用的tupled参数来查看它,即
member test.``When profitmarging is 10% and total is 200 expect 20 `` (x:int,y:int,z:int) =
答案 1 :(得分:1)
查看SimpleTestRunner
和RemoteTestRunner
,ala this question。