stryker-net icon indicating copy to clipboard operation
stryker-net copied to clipboard

Stryker.NET could not compile the project after mutation - MAUI

Open AaronBastian opened this issue 1 year ago • 5 comments

Describe the bug After the project mutation in a MAUI app, framework level calls such as InitializeComponent become unrecognized.

Logs Stryker.NET encountered a compile error in StrykerTest/StrykerTest/App.xaml.cs (at 6:2) with message: The name 'InitializeComponent' does not exist in the current context (Source code: InitializeComponent) Safe Mode! Stryker will flag mutations in App as compile error. Stryker.NET could not compile the project after mutation. This is probably an error for Stryker.NET and not your project. Please report this issue on github with the previous error message.

Expected behavior The MAUI app will continue to compile after mutations are run. MAUI specific methods, such as InitializeComponent will remain recognized after mutations.

Desktop (please complete the following information):

  • OS: MacOS 15.1.1
  • Type of project: MAUI
  • Framework Version: net8.0
  • Stryker Version: 4.5.1

Additional context I spent time struggling to get a MAUI app to pass analysis because the TargetFramework configuration option was ignored in the IProjectAnalyzer.Build() method. So I checked out the code, modified the analyzer to pass in the configured TargetFramework, and got past that step where mutations would actually run. This is the only set of code changes that I made.

AaronBastian avatar Mar 13 '25 12:03 AaronBastian

I spent time struggling to get a MAUI app to pass analysis because the TargetFramework configuration option was ignored in the IProjectAnalyzer.Build() method. So I checked out the code, modified the analyzer to pass in the configured TargetFramework, and got past that step where mutations would actually run. This is the only set of code changes that I made.

Regarding this, a proper fix is in PR #3184.

That being said, we know that Stryker is not able to build MAUI project and we do not know why yet.

dupdob avatar Mar 14 '25 17:03 dupdob

I wonder how much of this is happening because of the partial classes between XAML and code-behind because all of the errors that I am getting now deal with "InitializeComponent()" in views failing. If we were doing a C# level declarative UI, maybe the mutations will be less destructive to the compiler?

AaronBastian avatar Mar 17 '25 15:03 AaronBastian

That is likely part of the issue, code-behind often uses msbuild targets to execute the code generation and these targets may be skipped when Stryker compiles the project.

rouke-broersma avatar Mar 17 '25 15:03 rouke-broersma

I have created an empty MAUI project to get an idea of where the problem(s) could be.

Update: it works with an empty project.... 😢

Correction: not sure my first attempt was made on a proper project. I am trying to have a more realistic one. I am not able to have working unit tests yet.

dupdob avatar Mar 17 '25 15:03 dupdob

I was able to create a MAUI project that uses no XAML, and all views are declared in C# (Using MauiReactor). Then I created an xUnit test project for it, added a dummy service with one method, and then one unit test. The stryker mutation testing not only built the project correctly, it ran the mutation testing without issue.

To me, it seems like the issue inherently lies in *.xaml and *.xaml.cs files, as the compiler errors that happen in projects with those files all happen around the InitializeComponent() call in the code-behind constructors.

AaronBastian avatar Mar 24 '25 16:03 AaronBastian