Fail message on VerifyNoOtherCalls
I would like to have a message on tests when VerifyNoOtherCalls fails. It would be useful if you have a number of cases where the mock should not be called in a Theory.
Consider following (artificial) example, where it would be nice to have the failMsg printed in output if the test fails.
public class TestClass
{
private readonly ITestInterface component;
public TestClass(ITestInterface component)
{
this.component = component;
}
public void Caller(int value)
{
if (value < 2) return;
if (value > 43) return;
component.CallThis(value);
}
}
public interface ITestInterface
{
void CallThis(int value);
}
[Theory]
[InlineData(1, "Should not call component if less than 2")]
[InlineData(44, "Should not call component if bigger than 43")]
public void Test(int value, string failMsg)
{
var mock = new Mock<ITestInterface>();
var testable = new TestClass(mock.Object);
testable.Caller(value);
mock.VerifyNoOtherCalls();
}
In this (artificial) example, wouldn't it be sufficient to give a more meaningful name to the test method itself (say, Caller_does_not_invoke_component_for_values_not_between_2_and_43)? Your test runner would then output that method name for the test failure. Seems like a simpler solution than having to extend the tooling...
Yeah, it was a bad example. There are more complicated inputs where renaming the test is not as easy. But maybe we should duplicate the test into several facts instead, and give the tests more descriptive names.
@tengl, have you since found a solution that works for you (without us having to extend Moq), or do you still want to follow up on this?
@stakx Sorry for the late reply. I haven't been working in that part of the code for a while. But I guess that breaking the theory into several almost identical facts would solve the issue.
But I still think that a message would be nice to have, but not critical.
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.
This issue will now be closed since it has been labeled 'stale' without activity for 30 days.
