15

I am writing a script to build and test projects in a repository. For now I'm using the PowerShell command Get-ChildItem -Path test -Filter *.csproj -Recurse | ForEach-Object { dotnet test $_.FullName -c $Configuration } to get all .csproj files in my test folder and run the tests in them. However, I notice when I run, for example, dotnet test test/ProjectA/ProjectA.csproj I get this message:

A total of 1 test files matched the specified pattern.

Seeing this, I assumed it was possible to use a pattern to run tests in multiple projects with one command, but I can't find documentation for it or get it to work. When I try dotnet test test/**/*.csproj I get:

MSBUILD : error MSB1009: Project file does not exist.

Valuator
  • 3,262
  • 2
  • 29
  • 53

3 Answers3

13

It doesn't seem to be currently supported. For now, the closest alternative is to pass solution file path to the dotnet test command. That way, it will run all the tests from all the projects added to the solution.

dotnet test foo/bar.sln

Sateesh Pagolu
  • 9,282
  • 2
  • 30
  • 48
2

Consider using dotnet test --filter FullyQualifiedName!~YourTestNameOrPartName

Riddik
  • 2,565
  • 1
  • 11
  • 21
1

Pattern matching is currently not supported in this way. But you can simply call dotnet test without a further argument which automatically searches for test projects in the current directory (see the docs).

Dejan
  • 9,150
  • 8
  • 69
  • 117
  • 9
    That's actually not true. It only does if there's a solution file. If you do `dotnet test` inside a folder which just contain other folders it will not find the projects. Just running into this now and it sucks big time. From the docs: If not specified, it searches for a project or a solution in the current directory. – jpgrassi Jun 04 '20 at 12:41
  • dotnet test ./somesolution.sln . I have like 20 test projects in the solution, it is only finding one of the projects. Not sure why is not finding the other 19 – Andy N Jul 25 '23 at 17:40