CodexBloom - Programming Q&A Platform

Visual Studio 2022 - implementing Live Unit Testing Not Picking Up Changes in Partial Classes

👀 Views: 1951 💬 Answers: 1 📅 Created: 2025-06-09
visual-studio unit-testing partial-classes xunit C#

I've been banging my head against this for hours. Hey everyone, I'm running into an issue that's driving me crazy. I'm experiencing an scenario with Live Unit Testing in Visual Studio 2022 where it doesn't seem to pick up changes made to methods in partial classes. I have a partial class structure like this: ```csharp // File: MyClass.Part1.cs public partial class MyClass { public void Method1() { // Some code here } } // File: MyClass.Part2.cs public partial class MyClass { public void Method2() { // Some code here } } ``` I have unit tests set up using xUnit as follows: ```csharp public class MyClassTests { [Fact] public void TestMethod1() { var myClass = new MyClass(); myClass.Method1(); // Assertions } } ``` When I modify `Method1` in `MyClass.Part1.cs`, I would expect Live Unit Testing to re-run the tests associated with it. However, it seems to cache the previous implementation, and I see a message stating, "Tests are up to date" in the Live Unit Testing window. I've already tried clearing the cache and restarting Visual Studio, but the scenario continues. In the Live Unit Testing settings, I’ve ensured that the test project is included, and I’ve confirmed that the project builds without errors. Another point to note is that when I make changes in other classes or methods, Live Unit Testing works as expected. Has anyone else encountered this scenario, or does anyone have suggestions on how to troubleshoot this further? What's the best practice here? The stack includes C# and several other technologies. For reference, this is a production web app. What am I doing wrong? I'd love to hear your thoughts on this.