Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

During test discovery for DynamicData tests, environment variables defined in .runsettings files were not available to ITestDataSource implementations, causing tests to fail or display incorrect names in Test Explorer.

RunSettingsEnvironmentVariableProvider only checked the --settings command line option, ignoring environment variables used by VSTestBridge to pass runsettings configuration:

  • TESTINGPLATFORM_EXPERIMENTAL_VSTEST_RUNSETTINGS (inline XML)
  • TESTINGPLATFORM_VSTESTBRIDGE_RUNSETTINGS_FILE (file path)

Changes

  • Updated RunSettingsEnvironmentVariableProvider.IsEnabledAsync() to check environment variables in addition to command line option
  • Added cascading fallback: command line → inline XML env var → file path env var
  • Added comprehensive unit tests covering all runsettings sources

Example

internal class ExampleTestDataSource : Attribute, ITestDataSource
{
    public IEnumerable<object?[]> GetData(MethodInfo methodInfo)
    {
        // This now works during test discovery
        yield return new object[] { Environment.GetEnvironmentVariable("TEST_ENV") };
    }
}

With .runsettings:

<RunSettings>
  <RunConfiguration>
    <EnvironmentVariables>
      <TEST_ENV>TestValue</TEST_ENV>
    </EnvironmentVariables>
  </RunConfiguration>
</RunSettings>

Environment variables are now properly set during discovery, allowing data sources to access them.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 96bvsblobprodcus338.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/11.0.0-beta.25605.2.txt (dns block)
    • Triggering command: /usr/bin/dotnet dotnet build src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj --configuration Release (dns block)
  • rcxvsblobprodcus328.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj --configuration Release (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>runsettings are ignored during test discovery (data driven tests)</issue_title>
<issue_description>## Describe the bug

During test discovery of DynamicData tests (using the ITestDataSource), the <EnvironmentVariables> section of the selected .runsettings file is ignored.

Steps To Reproduce

  1. Implement the following:
    internal class ExampleTestDataSource : Attribute, ITestDataSource
    {
        public IEnumerable<object?[]> GetData(MethodInfo methodInfo)
        {
            yield return new object[] { Environment.GetEnvironmentVariable("TEST_ENV") };
        }

        public string? GetDisplayName(MethodInfo methodInfo, object?[]? data)
        {
            if (data != null)
            {
                var value = (string)data[0];
                return $"{methodInfo.Name} - {value}";
            }
            return null;
        }
    }

    [TestClass]
    public class MyTests
    {
        [TestMethod]
        [ExampleTestDataSource]
        public void MyTest(string name)
        {
            Assert.IsTrue(!string.IsNullOrEmpty(name));
        }
    }
  1. Create a .runnsettings file with the following section:
<RunSettings>
	<RunConfiguration>
		<EnvironmentVariables>
			<TEST_ENV>This is a string</TEST_ENV>
		</EnvironmentVariables>
	</RunConfiguration>
</RunSettings>
  1. Configure TestExplorer to use your .runsettings file.

  2. Observe that the test name (in test explorer) does not include the "This is a string" token.

  3. Observe that MyTest fails.

Expected behavior

.Runsettings to be used during test discovery.

Actual behavior

.runsettings is ignored during test discovery.

</issue_description>

Comments on the Issue (you are @copilot in this section)

@Youssef1313 The issue here is in VSTestBridge. The `RunSettingsEnvironmentVariableProvider` implementation doesn't consider `TESTINGPLATFORM_EXPERIMENTAL_VSTEST_RUNSETTINGS`.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix runsettings being ignored during test discovery Fix: runsettings environment variables ignored during test discovery Dec 7, 2025
Copilot AI requested a review from Evangelink December 7, 2025 16:16
Copilot finished work on behalf of Evangelink December 7, 2025 16:16
@Evangelink Evangelink marked this pull request as ready for review December 7, 2025 16:28
@Evangelink Evangelink enabled auto-merge (squash) December 7, 2025 16:28
Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually validated

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runsettings are ignored during test discovery (data driven tests)

2 participants