Pass parameters via the command line to NUnit

前端 未结 4 2077
不知归路
不知归路 2020-12-14 15:40

Is it somehow possible to pass values to NUnit tests via the command line?

My tests use a certain URL. I have different instances of my code at different URLs and wo

4条回答
  •  盖世英雄少女心
    2020-12-14 16:03

    NUnit 3 now allows passing parameters. Here is the usage

    nunit3-console [inputfiles] --params:Key=Value
    

    From the documentation

    --params|p=PARAMETER

    A test PARAMETER specified in the form NAME=VALUE for consumption by tests. Multiple parameters may be specified, separated by semicolons or by repeating the --params option multiple times. Case-sensitive.

    Here's how you can access the parameter through code:

    var value= TestContext.Parameters.Get("Key", "DefaultValue");
    

提交回复
热议问题