unoplatform / uno.templates

Uno Platform project templates
https://platform.uno/
Other
16 stars 11 forks source link

Changing code and running a unit test does not build the tested project automatically #670

Closed Zerachiel01 closed 4 months ago

Zerachiel01 commented 5 months ago

Current behavior

Hello everyone! I'm not sure if this is an uno platform issue, but I have not experienced this anywhere else.

I have a simple uno platform 5.2 app with a unit test project generated by a template. Now when I change some of my production code in the main project, for example adding a new method, call that method in a unit test and run that test, I get the "class does not contain a definition for 'MyMethod'" message in the build log. Visual Studio and the compiler recognize the new method as expected though. To get rid of this strange behaviour, I have to explicitly build the test project. The same issue appears if I change some lines inside a method or something like that.

It seems that Visual Studio (or whoever is responsible for that) does not see the need of rebuilding the changed(!) main project before running my test.

Expected behavior

If I change code in my main uno platform project and run a test using this changed code, Visual Studio is supposed to be rebuilding the main project, so that my test is using the up to date code.

How to reproduce it (as minimally and precisely as possible)

  1. Create a new uno platform app with unit tests
  2. Build and run tests
  3. Add a new method to an existing class
  4. Call the new method in a unit test
  5. Run the unit test calling the new method without explicitly building the test project or the main project

Workaround

Build the test project explicitly to trigger a build of the main project.

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

No response

IDE

Visual Studio 2022

IDE version

17.9.6

Relevant plugins

No response

Anything else we need to know?

No response

agneszitte commented 5 months ago

cc @jeromelaban, @dansiegel

dansiegel commented 4 months ago

This behavior seems to be Visual Studio specific. Making the same changes and then running dotnet test from the CLI works as expected.

dansiegel commented 4 months ago

@Zerachiel01 if you're able to update to 17.9.7 please let me know if this resolves the issue for you. I'm not able to reproduce the issue in 17.9.7 on my Mac with Parallels but I can on my PC with 17.9.6

Zerachiel01 commented 4 months ago

@dansiegel Upgrading to even 17.10.0 did not resolve the issue unfortunately.

As a work around I extracted some of my classes into separate class libraries. Tests of classes of these libraries work just fine, the problem only occurs for the main uno project.

jeromelaban commented 4 months ago

@Zerachiel01 this issue is related to this VS issue, and while this is a problem, with the latest changes we pushed a few days ago, you can get around testing by ensure that the debugger active target framework is set to net8.0. This will allow the app to build in the targetframework used by tests.

Zerachiel01 commented 4 months ago

@jeromelaban Thank you very much, works like a charm!