Skip to content

Assert.That is inconsistent in reporting the details of what is being called #6691

Closed

Description

@nohwnd

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 = ""

Activity

  1. added
    area/mstest
    on Oct 8, 2025
  2. Youssef1313 commented on Oct 8, 2025

    @Youssef1313
    Member
  3. added
    area/assertion
    on Oct 8, 2025
  4. added a commit that references this issue on May 19, 2026
  5. Evangelink commented on May 20, 2026

    @Evangelink
    Member

    Resolved by #8306 (which also addressed the sibling re-evaluation issue #6690). Assert.That now 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/assertionarea/mstest

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions