Reputation: 12675
I've got an api project that I'd like to run some integration tests on in the Azure release pipeline.
I'm stuck on step 4. It's easy to pass arguments to a test fixture in Visual Studio.
[TestFixture(arguments: "https://urltomyslot.azurewebsites.net")]
public class CachedClientApiTokenManagerTests
{
public CachedClientApiTokenManagerTests(string authority)
{
_authority = authority;
}
private readonly string _authority;
// Runs tests using the url
}
What I don't know how to do is passing arguments from Azure Devops based on environment. I'm using the NUnit3TestAdapter package and it runs fine, but the args is the sticking point. If we're doing this in our lab environment, the url passed is different from the staging or production urls.
How do we configure this in Azure DevOps with args?
Upvotes: 6
Views: 5469
Reputation: 129
You can configure runsettings file and override test parameters based on the environment.
Runsettings file :
<TestRunParameters>
<Parameter name="ApplicationUrl" value="https://qa.environment.url" />
</TestRunParameters>
You can access the test run parameters like :
string applicationUrl = TestContext.Properties["ApplicationUrl"];
How to override parameters in VsTest task in pipeline:
Upvotes: 4
Reputation: 41545
You can define the environment in the variables:
Then read the variables in the C# code with this way:
string environment = Environment.GetEnvironmentVariable("environment", EnvironmentVariableTarget.Process);
Now depend to the value of environment
create the URL and run the tests.
For example, I created a small Console Application:
class Program
{
static void Main(string[] args)
{
string environment = Environment.GetEnvironmentVariable("environment", EnvironmentVariableTarget.Process);
if (environment == "prod")
{
Console.WriteLine("We are in production :)");
}
}
}
I configured the variable:
And I run the .exe
file, in the output I can see the We are in production :)
printed:
Upvotes: 11