简体   繁体   中英

Running only certain canopy tests as specified on command line

Let's say I have the following simple Canopy test program:

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 . But sometimes, I'd like to only run test 3 .

What's the recommended way to set this up in 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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