-
Notifications
You must be signed in to change notification settings - Fork 11
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
Exceptions are swallowed/obscured #16
Comments
I'm fairly new to C# but what I think is happening is that the
So in the case of an exception from anything inside the |
You are right that a Unfortunately, this cannot really be fixed without fundamentally changing the syntactical usage pattern for Moq.Sequences. There are ways to work around this problem, though. Which one applies depends on what you need:
I think it goes without saying that you want to avoid (3). It's not exactly legible code. If possible, try to do something like in (1) or (2), i.e. handle any exceptions inside the |
In a unit test I do need to bubble up the underlying
This seems to work, my test failure includes the actual exception from |
It suspect that solving this problem properly would mean that the One possible alternative would be to use Sequence.Create(() =>
{
...
mock.DoStuff();
}); If the lambda throws, then the exception would bubble up (be rethrown by What do you think of that? |
Yes, that seems like a reasonable alternative for a situation like mine where a test can produce exceptions on its own. I would humbly suggest a better name for |
Yes, I was thinking the same, there would probably be a name that fits better than |
I'm thinking you could leave both usages intact, the new one would be useful for certain circumstances, while the other is familiar and (slightly) simpler). |
Moq.Sequences has one fudamental design flaw, namely that its syntax is based on `Dispose` which can then throw a method. `Dispose` should never throw methods; this can lead to previous exceptions being swall- owed, see dwhelan#16. This draft commit is a quick prototype of an alternative, `Action` lambda-based syntax that tries to do without `using` statements. Not done yet!
Moq.Sequences has one fudamental design flaw, namely that its syntax is based on `Dispose` which can then throw a method. `Dispose` should never throw methods; this can lead to previous exceptions being swall- owed, see dwhelan#16. This draft commit is a quick prototype of an alternative, `Action` lambda-based syntax that tries to do without `using` statements. Not done yet!
Moq.Sequences has one fudamental design flaw, namely that its syntax is based on `Dispose` which can then throw a method. `Dispose` should never throw methods; this can lead to previous exceptions being swall- owed, see dwhelan#16. This draft commit is a quick prototype of an alternative, `Action` lambda-based syntax that tries to do without `using` statements. Not done yet!
Did some quick prototyping over there, but not yet completely satisfied with the result due to the additional line noise from the lambdas. The I have also started wondering if it wouldn't be the better solution to separate the sequence setup and verify stages (with the mock exercising happening in-between). var sequence = Sequence.Setup(() =>
{
mock.Setup(…).InSequence();
});
… // exercise mock
sequence.Verify(); Which would obviously be quite a change, but solve the exception swallowing problem and probably a few others. I'll stop for now but will think about this some more later. |
@stakx separate sequence setup and verify stages is a good solution. Sequence checks are not working when I using the following block inside method which I'm testing.
Please, redesign library concept as you mentioned. |
In a simple usage like this:
If an exception is thrown from the
DoStuff()
method, the test will fail but with a sequence exception, hiding the actual exception fromDoStuff()
. It makes troubleshooting such tests very difficult. Basically I've had to comment-out all the Moq.Sequences stuff in order to get to the actual error.The text was updated successfully, but these errors were encountered: