Home > Software engineering >  How do I configure Visual Studio 2022 to exclude certain test types by default?
How do I configure Visual Studio 2022 to exclude certain test types by default?

Time:09-07

I currently manually add -trait="Integration" to the Test Explorer search to make sure I don't run any tests marked as Integration.

example teste explorer search

How can I make this the default?

CodePudding user response:

There doesn't seem to be a way to default this search, but I think a good solution to your problem is to make use of a playlist and add all of the tests with the "Integration" trait to the playlist.

  1. Right click in the "Tests" portion of the Test Explorer window and select Add to playlist → New playlist. This will open another text explorer window with your newly created playlist.
  2. Click the pencil icon to edit the playlist
  3. Filter using the search bar on your trait criteria.
  4. Select all the tests you wish to add to the playlist (probably all of them in this case).
  5. Save the playlist using the floppy disk icon.

playlist

You can even pin this playlist window like any other window. The only downside to this is you have to continue to add new tests to it as you go. However that should be fairly easy to do via these steps.

CodePudding user response:

You could define the filter in a vstest.runsettings file:

<RunSettings>
    <RunConfiguration>
        <TestCaseFilter>TestCategory!=Integration</TestCaseFilter>
    </RunConfiguration>
</RunSettings>

The TestCaseFilter element uses the same syntax as the command line expression used in dotnet test --filter (https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests?pivots=mstest).

  • Related