Completed
Last Updated: 10 Mar 2022 09:29 by ADMIN
Ivo
Created on: 30 Nov 2021 14:39
Type: Bug Report
0
Received wrong warning message

Considering the following simple scenario:

public class Class1
{
	private string arg1;

	public Class1(string arg1)
	{
		this.arg1 = arg1;
	}

	public Class3 Method(string arg)
	{
		throw new NotImplementedException();
	}
}

public class Class2
{
	static Class3 class3Instance; 

	public static void StaticMethod(string arg1, string arg2)
	{
		Class1 class1Instance = new Class1(arg1);
		class3Instance = class1Instance.Method(arg2);
	}
}

public class Class3
{

}

[TestClass]
public class Class2Test
{
	static Class1 mockClass1 = Mock.Create<Class1>();
	Class3 mockClass3 = Mock.Create<Class3>();

	[TestInitialize]
	public void SetUp()
	{
		Mock.Arrange(() => new Class1("arg1")).Returns(mockClass1);
		Mock.Arrange(() => mockClass1.Method("arg2")).Returns(mockClass3);
	}

	[TestMethod]
	public void TestB()
	{
		Class2.StaticMethod("arg1", "arg2");
	}
}

The test passes, but the debug trace output contains the warning message: "Calling one test method from another could result in unexpected behavior and must be avoided. Extract common mocking logic to a non-test method." even there is no call to the other test methods.

0 comments