Skip to content

RunSettingsArguments.md does not mention how to handle semicolons in test parameters, e.g. connection strings #15332

@jnm2

Description

@jnm2

https://github.com/Microsoft/vstest/blob/main/docs/RunSettingsArguments.md mentions that the way to pass test parameters at the dotnet test command line is to use "TestRunParameters.Parameter(name=\"...", value=\"...\")" parameters after --.

It would be helpful to include instructions on what to do if semicolons in the test parameter value are getting replaced with spaces when accessed by the test. What's going on is that VSTestTask2.VSTestCLIRunSettings is a string[] property, and so the input to it is split on any ;.

The fix is to replace ; with %3B at the command line inside the test parameter value.

This is no fun when generating connection strings dynamically in build scripts. If there's any possibility of allowing this scenario to "just work" so that people don't have to use %3B at the command line inside their test parameter values, that would be awesome. Otherwise, docs on this would really help.

Example

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
    <PackageReference Include="NUnit" Version="4.4.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
  </ItemGroup>

</Project>
using NUnit.Framework;

public class Tests
{
    [Test]
    public void Repro()
    {
        Assert.That(TestContext.Parameters["connectionString"], Is.EqualTo("A=B;C=D"));
    }
}

In cmd.exe:
dotnet test -- "TestRunParameters.Parameter(name=\"connectionString\", value=\"A=B;C=D\")":

String lengths are both 7. Strings differ at index 3.
Expected: "A=B;C=D"
But was:  "A=B C=D"
--------------^

To get the test to pass, use %3B at the command line:
dotnet test -- "TestRunParameters.Parameter(name=\"connectionString\", value=\"A=B%3BC=D\")":

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions