【问题标题】:Running only certain canopy tests as specified on command line仅运行命令行中指定的某些树冠测试
【发布时间】:2021-04-13 22:51:44
【问题描述】:

假设我有以下简单的Canopy 测试程序:

open System
open canopy.runner.classic
open canopy.configuration
open canopy.classic

canopy.configuration.chromeDir <- System.AppContext.BaseDirectory

start chrome

"test 1" &&& fun _ ->

    ...

"test 2" &&& fun _ ->

    ...

"test 3" &&& fun _ ->

    ...

[<EntryPoint>]
let main args =
    
    run()

    quit()

    0

当我运行这个程序时:

dotnet run

所有三个测试都运行。

假设默认情况下,我想运行test 1test 2。但有时,我只想运行test 3

在 Canopy 中进行此设置的推荐方法是什么?

传递命令行选项之类的就可以了:

dotnet run               # Run the default tests

dotnet run -- test-3     # Run test 3

或者,我想我可以让test 3 成为一个完全独立的项目。但这似乎只是为了进行单独的测试而产生的大量开销。

感谢您的任何建议!

【问题讨论】:

    标签: f# canopy-web-testing


    【解决方案1】:

    我认为没有任何内置方法可以做到这一点,但手动管理似乎很容易:

    let defaultTests () =
        "test 1" &&& fun _ -> ()
        "test 2" &&& fun _ -> ()
    
    let test3 () =
        "test 3" &&& fun _ -> ()
    
    [<EntryPoint>]
    let main (args : _[]) =
        let arg =
            if args.Length = 0 then "default"
            else args.[0]
        match arg with
            | "default" -> defaultTests ()
            | "test-3" -> test3 ()
            | _ -> failwith $"Unknown arg: {arg}"
        run()
        quit()
        0
    

    诀窍是确保只有您想要运行的测试在运行时才真正得到定义。

    【讨论】:

    • 很好的答案,布赖恩!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-03-13
    • 2016-07-11
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多