简体   繁体   English

仅运行命令行中指定的某些树冠测试

[英]Running only certain canopy tests as specified on command line

Let's say I have the following simple Canopy test program:假设我有以下简单的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

When I run this program:当我运行这个程序时:

dotnet run

All three tests are run.所有三个测试都运行。

Let's say that by default, I want to run test 1 and test 2 .假设默认情况下,我想运行test 1test 2 But sometimes, I'd like to only run test 3 .但有时,我只想运行test 3

What's the recommended way to set this up in Canopy?在 Canopy 中进行设置的推荐方法是什么?

Something like passing command line options would be fine:像传递命令行选项这样的东西会很好:

dotnet run               # Run the default tests

dotnet run -- test-3     # Run test 3

Alternatively, I guess I could have test 3 be in a whole separate project.或者,我想我可以将test 3放在一个单独的项目中。 But that seems like alot of overhead just to have a separate test.但这似乎只是为了进行单独的测试而产生的大量开销。

Thanks for any suggestions!感谢您的任何建议!

I don't think there's any built-in way to do this, but it seems pretty easy to manage manually:我认为没有任何内置方法可以做到这一点,但手动管理似乎很容易:

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

The trick is to make sure that only the tests you want to run actually get defined at run-time.诀窍是确保只有您想要运行的测试在运行时才真正得到定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM