【问题标题】:F# Running NUnit TestsF# 运行 NUnit 测试
【发布时间】:2015-03-02 16:04:02
【问题描述】:

我希望只运行一些单元测试,我已将它们添加到 .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 文件的入口点调用这些测试?

【问题讨论】:

    标签: f# nunit


    【解决方案1】:

    不久前,我构建了一个 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) =
    

    【讨论】:

      【解决方案2】:

      看看SimpleTestRunnerRemoteTestRunner,阿拉this question

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-03-04
        • 2018-08-30
        • 2011-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多