One of you e-mailed me recently commenting on the article I wrote a while ago about VSTest run settings.
They quite rightly pointed out that most people “nowdays” 😉 don’t use VSTest anymore because they choose ASP.NET Core or another framework as a basis of their application, where VSTest doesn’t make sense.
I therefore wanted to write an article showing how we can achieve the same thing using alternative frameworks and ASP.NET Core.
I started with XUnit, and it quickly turned out that this framework isn’t very “helpful” for this particular scenario. The convention is to use environment variables to change values on the fly. This is fine if you are running the tests on your own (private) test agents, but if you are using Azure Pipelines and hosted agents your environment variables will not be set. (This is due to missing admin rights)
Obviously we can write functional tests using XUnit. Below is an example of Selenium tests written in XUnit…
…but if our end goal is to pass parameters into .NET Core tests, then we’re better off using a different framework. Especially if we don’t have the option of using environment variables.
MSTest is a good option here as it supports runsettings. This allows us to both override settings using the VSTest task in Azure Pipelines, and also pass a different runsettings file at runtime, if we need to.
NUnit has built in support for providing parameters on the command line. If you are using the Azure Pipelines task and/or Visual Studio with NUnit you can even use the runsettings format. This is because the VSTest task and Visual Studio translate the runsettings into the command line format that NUnit looks for.