Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read .runsettings test parameter in xUnit fixture

I'm writing xUnit unit test cases for a dotnet core application which uses DocumentDB (CosmosDB) as storage. The unit test are written to execute against the local cosmos db emulator. On the Azure DevOps build environment, I've setup the Azure Cosmos DB CI/CD task which internally creates a container to install the emulator. However, I'm not able to figure out that how the endpoint of emulator can be passed to xUnit fixture?

Is there any way through which xUnit fixture can read the .runsettings test parameters or parameters can be passed via other source?

Update

Currently, I implemented the scenario using Environment Variable but still not happy to define the connection string as a environment variable using powershell in build task and read it in through code during unit test execution. I was thinking if there could be another way of achieving it..

Below snapshot shows how the build tasks are configured currently as workaround to achieve the desired: enter image description here

And code to read the value as

var serviceEndpoint = Environment.GetEnvironmentVariable("CosmosDbEmulatorEndpointEnvironmentVariable");

Since, UnitTest task provides the option to pass .runsettings/.testsettings with option to override the test run parameters so was thinking it something can be achieved using those options.

like image 406
user1672994 Avatar asked Mar 04 '19 06:03

user1672994


2 Answers

This is not supported in xUnit.

See SO answers here and here, and this github issue indicating that it is not something that will be supported in xUnit.

like image 150
Asbjørn Avatar answered Oct 15 '22 16:10

Asbjørn


Currently, I implemented the scenario using Environment Variable but still not happy to define the connection string as a environment variable using powershell in build task and read it in through code during unit test execution. I was thinking if there could be another way of achieving it..

Below snapshot shows how the build tasks are configured currently as workaround to achieve the desired: enter image description here

And code to read the value as

var serviceEndpoint = Environment.GetEnvironmentVariable("CosmosDbEmulatorEndpointEnvironmentVariable");

Since, UnitTest task provides the option to pass .runsettings/.testsettings with option to override the test run parameters so was thinking it something can be achieved using those options.

like image 41
user1672994 Avatar answered Oct 15 '22 18:10

user1672994