2

In Visual Studio Code, I am really confused by the 3 "Context" menu items: Run Tests in Context and Debug Tests in Context and Run .NET Core Test in context, what Context are they expecting?

enter image description here

In my understanding, TestContext will be initialized via .runsettings, but I am never able to pass the runsettings on Debugging/Running Tests in Context from VS code.

    [ClassInitialize]
    public static new void ClassInitialize(TestContext testContext)
    {
        //testContext doesn't get setting from `.runsettings`
        ...
        BaseTest.ClassInitialize(testContext);
    }

I believe the following Debug Test is different with Debug Tests in Context? because the follow Run Test can load runsettings, but Debug Test doesn't work.

enter image description here

Above Run Test work with following settings:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <RunSettingsFilePath>$(MSBuildProjectDirectory)\example.runsettings</RunSettingsFilePath>
  </PropertyGroup>
  ...
</Project>

My tests work well in Visual Studio 2019, but stuck in VS Code on loading .runsettings.

For more details:

Here is my folder structure:

enter image description here

Here is the content of workspace.code-workspace, and dotnet-test-explorer works well with it to load all tests:

{
    "folders": [
        {
            "path": ".."
        }
    ],
    "settings": {
        "dotnet-test-explorer.testArguments": "--settings c:/src/pat-oas/.runsettings",
        "dotnet-test-explorer.testProjectPath": "./tests/Pat.UITests.Itrds/Pat.UITests.Itrds.csproj"
    }
}
Dongdong
  • 2,208
  • 19
  • 28

1 Answers1

3

Running or Debugging tests in context is a visual studio feature that lets you run the tests from where the cursor is. It will run the first test going up from where the cursor is, or all tests in the file.

For vscode, the context to start looking for tests is where you right click. It just makes it easier than having to scroll up to the codelens, or find the test in an extension test runner.

runsettings is an omnisharp feature and you have to set the filepath under omnisharp.testRunSettings. Here is the relevant PR https://github.com/OmniSharp/omnisharp-vscode/pull/3573

.Net Core run test in context is probably contributed by an extension test runner you use.

You can view a diagram in this answer here https://stackoverflow.com/a/42881612

jmmendez
  • 91
  • 1
  • 3