stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.76k stars 175 forks source link

"System.InvalidOperationException: Sequence contains no elements" when running dotnet stryker #2671

Closed detilium closed 11 months ago

detilium commented 11 months ago

Describe the bug I've setup a completely new solution including a test project (xUnit) running .NET 6, without any unit tests.

I installed Stryker in the project using dotnet new tool-manifest and dotnet tool install dotnet-stryker.

I've then tried to run the dotnet stryker command both from the root of the solution folder, as well as from the root of the test project folder. Both are resulting in the same exception below:

dotnet : Unhandled exception. System.InvalidOperationException: Sequence contains no elements
At line:1 char:1
+ dotnet stryker
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Unhandled excep...ins no elements:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Stryker.Core.Initialisation.ProjectOrchestrator.MutateProjects(StrykerOptions options, IReporter reporters, ITestRunner runner)+MoveNext() in /_/src/Stryker.Core/Stryker.Core/Initialisation/ProjectOrchestrator.cs:line 57
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Stryker.Core.StrykerRunner.RunMutationTest(IStrykerInputs inputs, ILoggerFactory loggerFactory, IProjectOrchestrator projectOrchestrator) in /_/src/Stryker.Core/Stryker.Core/StrykerRunner.cs:line 61
   at Stryker.CLI.StrykerCli.RunStryker(IStrykerInputs inputs) in /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:line 93
   at Stryker.CLI.StrykerCli.<>c__DisplayClass10_0.<Run>b__0() in /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:line 68
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass143_0.<OnExecute>b__0(CancellationToken _)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Stryker.CLI.StrykerCli.Run(String[] args) in /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:line 74
   at Stryker.CLI.Program.Main(String[] args) in /_/src/Stryker.CLI/Stryker.CLI/Program.cs:line 14

Logs

2023-09-14T13:55:42.8678990+02:00  [DBG] Stryker started with options: StrykerOptions { MsBuildPath: null, DevMode: False, ProjectPath: "C:\DevOps Workspace\voucher-api", IsSolutionContext: True, WorkingDirectory: "C:\DevOps Workspace\voucher-api", OutputPath: "C:\DevOps Workspace\voucher-api\StrykerOutput\2023-09-14.13-55-42", ReportPath: "C:\DevOps Workspace\voucher-api\StrykerOutput\2023-09-14.13-55-42\reports", ReportFileName: "mutation-report", SolutionPath: "C:\DevOps Workspace\voucher-api\Voucher.sln", TargetFramework: null, LogOptions: LogOptions { LogToFile: True, LogLevel: Information }, MutationLevel: Standard, Thresholds: Thresholds { High: 80, Low: 60, Break: 0 }, AdditionalTimeout: 5000, LanguageVersion: Default, Concurrency: 6, SourceProjectName: "", TestProjects: [], TestCaseFilter: "", Reporters: [Progress, Html], WithBaseline: False, BaselineProvider: Disk, AzureFileStorageUrl: "", AzureFileStorageSas: "", DashboardUrl: "https://dashboard.stryker-mutator.io", DashboardApiKey: null, Since: False, SinceTarget: "master", DiffIgnoreChanges: [], FallbackVersion: "master", ModuleName: "", ReportTypeToOpen: null, Mutate: [FilePattern { Glob: Glob { Tokens: [WildcardDirectoryToken { TrailingPathSeparator: PathSeparatorToken { Value: \ }, LeadingPathSeparator: null }, WildcardToken {  }] }, IsExclude: False, TextSpans: [TextSpan { Start: 0, End: 2147483647, Length: 2147483647, IsEmpty: False }] }], IgnoredMethods: [], ExcludedMutations: [], ExcludedLinqExpressions: [], OptimizationMode: CoverageBasedTest, ProjectName: "", ProjectVersion: "", BreakOnInitialTestFailure: False } (fac41b16)
2023-09-14T13:55:42.8989146+02:00  [INF] Analysis starting. (7076a364)
2023-09-14T13:55:42.9019420+02:00  [INF] Identifying projects to mutate in "C:\DevOps Workspace\voucher-api\Voucher.sln". This can take a while. (352fa797)
2023-09-14T13:55:42.9352917+02:00  [DBG] Analyzing 4 projects. (a101d45b)
2023-09-14T13:55:42.9371345+02:00  [DBG] Analyzing "src\Voucher.Api\Voucher.Api.csproj" (1defaf37)
2023-09-14T13:55:42.9372559+02:00  [DBG] Analyzing "tests\Voucher.Tests.Unit\Voucher.Tests.Unit.csproj" (1defaf37)
2023-09-14T13:55:42.9374208+02:00  [DBG] Analyzing "src\Voucher.Core\Voucher.Core.csproj" (1defaf37)
2023-09-14T13:55:42.9376672+02:00  [DBG] Analyzing "src\Voucher.Data.Mssql\Voucher.Data.Mssql.csproj" (1defaf37)
2023-09-14T13:55:44.3567921+02:00  [DBG] Analysis of project "src\Voucher.Data.Mssql\Voucher.Data.Mssql.csproj" succeeded. (adaf2e80)
2023-09-14T13:55:44.4076081+02:00  [DBG] Analysis of project "src\Voucher.Core\Voucher.Core.csproj" succeeded. (adaf2e80)
2023-09-14T13:55:44.5557094+02:00  [DBG] Analysis of project "tests\Voucher.Tests.Unit\Voucher.Tests.Unit.csproj" succeeded. (adaf2e80)
2023-09-14T13:55:44.6881292+02:00  [DBG] Analysis of project "src\Voucher.Api\Voucher.Api.csproj" succeeded. (adaf2e80)
2023-09-14T13:55:44.6927275+02:00  [INF] Found 3 source projects (c1ce5c69)
2023-09-14T13:55:44.6928587+02:00  [INF] Found 1 test projects (6f0fd09d)
2023-09-14T13:55:44.6965453+02:00  [WRN] Project "src\Voucher.Api\Voucher.Api.csproj" will not be mutated because Stryker did not find a test project for it. (b4dae632)
2023-09-14T13:55:44.6966472+02:00  [WRN] Project "src\Voucher.Core\Voucher.Core.csproj" will not be mutated because Stryker did not find a test project for it. (b4dae632)
2023-09-14T13:55:44.6967040+02:00  [WRN] Project "src\Voucher.Data.Mssql\Voucher.Data.Mssql.csproj" will not be mutated because Stryker did not find a test project for it. (b4dae632)
2023-09-14T13:55:44.6967551+02:00  [INF] Analysis complete. (f039f576)
2023-09-14T13:55:44.6978132+02:00  [INF] Building solution "Voucher.sln" (abcf88bf)
2023-09-14T13:55:44.6985319+02:00  [DBG] Started initial build using "dotnet build" (a4e1a5e2)
2023-09-14T13:55:44.6985645+02:00  [DBG] Initial build using path: "C:\DevOps Workspace\voucher-api\Voucher.sln" (657c8664)
2023-09-14T13:55:47.2054470+02:00  [DBG] Initial build successful (61599426)
2023-09-14T13:55:47.2099186+02:00  [INF] Time Elapsed 00:00:04.3777753 (f4427d77)
2023-09-14T13:55:47.2387386+02:00  [DBG] VsTest zip was copied to: "C:\Users\chaa\AppData\Local\Temp\0twsxutd.m5i\.vstest\vstest.zip" (8e340ff1)

Expected behavior I would expect Stryke to just inform that there are no tests in the project, then end execution without any exceptions.

Desktop (please complete the following information):

Additional context I've followed the "Getting started" guide from stryker-mutator.io without any exceptions.

I've tried installing "NuGet targets and build tasks" even though I'm not running .NET Framework.

I've upgrading my Visual Studio 2022 to the latest version (v17.7.4).

rouke-broersma commented 11 months ago

Agreed that this should be a cleaner error, however I don't think the error is caused by having no unit tests:

2023-09-14T13:55:44.6927275+02:00  [INF] Found 3 source projects (c1ce5c69)
2023-09-14T13:55:44.6928587+02:00  [INF] Found 1 test projects (6f0fd09d)
2023-09-14T13:55:44.6965453+02:00  [WRN] Project "src\Voucher.Api\Voucher.Api.csproj" will not be mutated because Stryker did not find a test project for it. (b4dae632)
2023-09-14T13:55:44.6966472+02:00  [WRN] Project "src\Voucher.Core\Voucher.Core.csproj" will not be mutated because Stryker did not find a test project for it. (b4dae632)
2023-09-14T13:55:44.6967040+02:00  [WRN] Project "src\Voucher.Data.Mssql\Voucher.Data.Mssql.csproj" will not be mutated because Stryker did not find a test project for it. (b4dae632)

It seems your unit test project does not reference any source project at all, this likely causes the issue. We are finding 'no project to mutate'. This should be handled gracefully.

detilium commented 11 months ago

Ah yes that resolved the error.

Agreed, would be nice with a user friendly error message :)

Thank you for your quick response.

dupdob commented 11 months ago

I think the fix is in master now, but as yet to be delivered. And I think that it covers this situation

detilium commented 11 months ago

That sounds perfect. I'm closing this issue then.

Again thank you for the fast response.