Repository navigation
Closed
Labels
area/assertionAssert / StringAssert / CollectionAssert APIs.area/mstestMSTest framework (not analyzers or assertions).
Milestone
Description
Describe the bug
When calling method in expression, the output differs when I run an instance method, or static method, it also reports different amount of detail when using instance method on the same type (the test class), or on other type.
Making it hard to identify where the static method comes from, and overreporting on local methods on the test class.
Steps To Reproduce
using System.Diagnostics.CodeAnalysis;
namespace mstest280;
[TestClass]
public sealed class Test1
{
[TestMethod]
public void SameType_Instance()
{
string animal = "";
Assert.That(() => GetAnimal() == animal);
}
[TestMethod]
public void SameType_Static()
{
string animal = "";
Assert.That(() => GetAnimal2() == animal);
}
[TestMethod]
public void OtherType_Instance()
{
string animal = "";
var zoo = new Zoo();
Assert.That(() => zoo.GetAnimal() == animal);
}
[TestMethod]
public void OtherType_Static()
{
string animal = "";
Assert.That(() => Zoo.GetAnimal2() == animal);
}
public string GetAnimal()
{
return "Giraffe";
}
public static string GetAnimal2()
{
return "Giraffe";
}
}
public class Zoo
{
public string GetAnimal()
{
return "Giraffe";
}
public static string GetAnimal2()
{
return "Giraffe";
}
}Expected behavior
We see
this.GetAnimal() <- instance on same type
Test1.GetAnimal2() <- static on same type
zoo.GetAnimal() <- instance on other type
Zoo.GetAnimal2() <- static on other type
Actual behavior
Failed SameType_Static [52 ms]
Error Message:
Assert.That(() => GetAnimal2() == animal) failed.
Details:
GetAnimal2() = "Giraffe" <- type is not seen
animal = ""
Failed SameType_Instance [52 ms]
Error Message:
Assert.That(() => GetAnimal() == animal) failed.
Details:
animal = ""
mstest280.Test1.GetAnimal() = "Giraffe" <- project name is seen
Failed OtherType_Instance [52 ms]
Error Message:
Assert.That(() => zoo.GetAnimal() == animal) failed.
Details:
animal = ""
zoo.GetAnimal() = "Giraffe" <- correct
Failed OtherType_Static [52 ms]
Error Message:
Assert.That(() => Zoo.GetAnimal2() == animal) failed.
Details:
GetAnimal2() = "Giraffe" <- type is not seen
animal = ""
Metadata
Metadata
Assignees
Labels
area/assertionAssert / StringAssert / CollectionAssert APIs.area/mstestMSTest framework (not analyzers or assertions).
Activity
Youssef1313 commentedon Oct 8, 2025
FYI Amaury Levé (@Evangelink)
Fix Assert.That: single-pass evaluation (#6690) and consistent method…
Evangelink commentedon May 20, 2026
Resolved by #8306 (which also addressed the sibling re-evaluation issue #6690).
Assert.Thatnow produces a consistent reconstructed call-site display regardless of whether the expression contains instance or static method calls, on the test class or on another type.Closing as completed — please re-open with a fresh repro if you still see asymmetry.
Assert.That: restore friendly method-call display from #6691 (#8364)