I have a .NET Core MSTest library, and I would like to pass a parameter to it on the command line. Something like this:
dotnet test -myparam=myvalue
How would I do something like this, and how would I retrieve the value of "myparam" in code.
Note: I would be ok with somehow specifying a configuration file for the test library to use, rather than just passing a parameter.
You can use the .runsettings file to send custom parameters. For example, I could have the following run settings file:
<RunSettings>
<TestRunParameters>
<Parameter name="foo" value="bar" />
</TestRunParameters>
</RunSettings>
You can then access it through the TestContext:
public TestContext TestContext { get; set; }
[TestMethod]
public void TestMethod1()
{
Assert.AreEqual("bar", TestContext.Properties["foo"]);
}
Finally, you specify the runsettings file on the command line using the --settings argument:
dotnet test --settings test.runsettings
Note: There is support for passing some runsettings parameters in via the command line, but it looks like the support is rather basic at this time and it appears that you can't pass TestRunParameters in this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With