question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weaving not applied during Live Unit Testing

See original GitHub issue

Bit new to Fody so pls go easy. There are a few moving parts to this that I’ve tried as a result of reading various posts/articles. I’m unsure if this is an issue with PropertyChanged.Fody or if Fody in its entirety is not being executed under LUT scenarios. Happy to post to another location if that’s appropriate but thought I’d start at the highest level of specificity.

Environment

I have a basic soln structure as follows:

  • VS 2022 (17.0.0 Preview 5)
  • C# Library project (sdk=Microsoft.Net.Sdk) targeting net6.0
  • MSTest v2 library targeting same
  • Library project has a base (abstract) class with INotifyPropertyChanged and protected virtual void OnPropertyChanged( string propertyName )
  • Test library has a class that inherits from the base and implements a basic string property (auto-implemented)
  • All projects have FodyWeavers.xml in the root with the <PropertyChanged /> element added
  • There are no other weavers present
  • All projects have references as follows:
<PackageReference Include="Fody" Version="6.5.3">
	<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody" Version="4.0.0">
	<PrivateAssets>all</PrivateAssets>
</PackageReference>

Problem

Nothing I can do will make OnPropertyChanged() fire in the context of Live Unit Testing. I can get it to work when running through Test Explorer and via dotnet test so this isn’t an issue with the normal operation of the library per se.

I have been unable to identify a discrepancy between the build process used in LUT/roslyn and the normal dotnet build/msbuild so I can’t imagine why it wouldn’t work, hoping someone with experience in this area can direct me to whatever changes might be necessary to get LUT going.

Observation: Fody & PropertyChanged.Fody packages need to be applied to both the library project AND the MSTest project in order for it to work through Test Explorer - I would not have expected this to be the case, but may be a clue. Presumably these references are only required on the project that actually uses the weaving?

Anyone have any suggestions or thoughts?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
richardhauercommented, Oct 18, 2021

Most of my tests were against classes that were not defined in the Test library. It happens that the first test was setup that way as I was testing the base class’ ability to record changed properties so I can have a IsChanged( a => a.Prop ) method that would inherit into all the models I need.

I had subsequently created a number of tests against the real models, all of which are in the Library project as you’d expect, and these had tests that passed when debugged or run in Test Explorer, but failed under LUT. With my changes to the target all the tests now pass under all conditions.

1reaction
tom-englertcommented, Oct 18, 2021

@richardhauer

  • Test library has a class that inherits from the base and implements a basic string property (auto-implemented)

I think this could be the root cause, the class you are testing is in the test library! At least that is the reason why you need PropertyChanged.Fody in the test project!

Read more comments on GitHub >

github_iconTop Results From Across the Web

AspectJ not weaving on test-compile but ...
AspectJ not weaving on test-compile but weaves on compile. Therefore unit tests throw ClassNotFoundException when running with maven.
Read more >
FodyTarget condition excluding use during ...
It seems that VS builds for Live Unit Testing with the DesignTimeBuild flag set. The condition in the targets file is preventing weaving ......
Read more >
Configure and use Live Unit Testing - Visual Studio
Learn about Live Unit Testing during application development, including supported frameworks and how to configure Live Unit Testing.
Read more >
Testing Times at Weaveworks
We like continuous integration and testing at Weaveworks. This blog post tells the story of the journey we have been through, the tools...
Read more >
Unit-Tests and databases: At which point do I actually ...
I disagree. A test requiring a database connection is not a unit test, because the test by its very nature will have side...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found