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?
In an open test case, select Convert to shared parameters. After you've created a shared parameter set, open another test case and add the shared parameter set to that test case. You can search for the shared parameter set by name. The shared parameter set is displayed in the Parameter values section after you add it.
Share variables between Tasks across the Jobs (of the same Stage) We need to use the isOutput=true flag when you desire to use the variable in another Task located in another Job. Navigate to Stage1_Job1_Task1 and add isoutput = true flag to the Logging Command which let's us to access the value outside the Job.
From the web portal, open your project and select Test Plans > Test plans. Select Mine or All, or use Filter by title to find your test plan and select it. Select the Execute tab. Launch Test Runner from Azure Test Plans by selecting Run for desktop application from the dropdown menu.
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:
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:
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