-
-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify() with custom failure message #650
Comments
If I understand you correctly, you would like to inject additional information not specific to any one particular setup into the verification error message, and the proposed I don't think that this functionality has to be provided by Moq. The unit testing framework of your choice likely already gives you the means to log additional information per test:
In my opinion it would be preferable to just use these mechanisms instead of reinventing the wheel in Moq. While Example for xUnit.net and Visual Studio:using Moq;
using Xunit;
using Xunit.Abstractions;
public interface IFrobbler
{
void Frobble();
}
public class Tests
{
private ITestOutputHelper log;
public Tests(ITestOutputHelper log)
{
this.log = log;
}
[Fact]
public void FailingTest()
{
this.log.WriteLine("(Random number generator seed goes here.)");
var mock = new Mock<IFrobbler>();
mock.Setup(m => m.Frobble());
mock.VerifyAll();
}
} |
I did not realize there was a Your argument that setup-specific probably makes more sense. While in my case I would have the same information for each |
To be clear, I wasn't saying that you should use I'm glad you found a solution that works for you. I'll close this then. |
When using
Verifiable()
setups, a call toVerify()
is used without any parameters to verify that the expected calls were made. However, sometimes I would like to put a custom failure message to include some extra data (for example, a RNG seed that generated the data for the test).The other overloads of
Verify()
support afailMessage
parameter, but there does not appear to be anyVerify(string failMessage)
which would be used for tests that useVerifiable()
.It would be nice if we could add this in. (When I find some free time I might just implement this and make a PR for this, but I wanted to at least get some thoughts on it first, because perhaps there's a reason this is missing.)
The text was updated successfully, but these errors were encountered: