How to read .runsettings test parameter in xUnit fixture
Asked Answered
T

2

13

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.

Tchao answered 4/3, 2019 at 6:12 Comment(0)
T
2

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.

Tchao answered 9/3, 2019 at 16:17 Comment(0)
L
9

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.

Lillalillard answered 29/3, 2019 at 14:3 Comment(0)
T
2

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.

Tchao answered 9/3, 2019 at 16:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.