-
Notifications
You must be signed in to change notification settings - Fork 746
Multiple Assertions #391
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
Comments
I'll throw my vote in here 👍 Mulitple asserts make unit testing purists cringe, but we use them in some long running integration tests. As you said, they can give you a lot more information about failing integration tests. |
Me too. I guess Rob's comment about purists refers to the "Single Assert" Let's use this issue to figure out the syntax we want to support. Some
From what you write, I'm assuming that MbUnit uses an action delegate or The key issue for all implementations is how we tell Assert that it is I'd like to see us get this into 3.0 in some form or another, so let's Charlie On Thu, Nov 27, 2014 at 7:16 AM, Rob Prouse notifications@github.com
|
(Samples taken from http://blog.bits-in-motion.com/search?q=mbunit) There are two ways to do this in MbUnit. Tag the method with [MultipleAsserts]: Or use the Assert.Multiple function and pass in a delegate: The MultipleAssertsAttribute is useful when UI testing a wizard and verifying its screens' default states. With the use of [MultipleAsserts], I should be able to verify the default states of the elements on screen 1, click next then verify the states on screen 2, click next, etc. |
I really like both of these.Let's call it a 3.0 feature... I haven't assigned it to a milestone yet... we'll be doing a planning session after the alpha-3 release. |
I've been playing around with this. Here are some thoughts: Assertions generate a ConstraintResult. We'll need some kind of MultipleConstraintResult that will bundle a collection of failing results and report all those results at the end of the block. The following should always terminate the test, even in a Multiple block: The same goes for assumptions. The purpose of assumptions (Assume.That) is to prevent execution of subsequent assertions. If we allow any of the above in a block, we need to specify what to do for each of them if they are encountered with pending failures accumulated. If we add warnings (as is planned) to NUnit 3.0 we'll have to accumulate them as well, reporting them at the end of the test. |
I haven't done any coding, but I was looking at this a bit too. I agree On 5 December 2014 at 02:03, CharliePoole notifications@github.com wrote:
Rob Prouse I welcome VSRE emails. Learn more at http://vsre.info/ |
Hi Rob, I was focused on how it should appear to users. For the implementation, we Taking it a step further, We throw ResultExceptions in various places. It I'm thinking that each place where we now throw should instead report the I would expect to need a small object constructed in a using statement to This centralized reporting is something we need for several other reasons But getting back to how it looks to users, we're left with some I think I should probably pick some answers and write a spec to be FYI, I'm blocked waiting for info from the developer of Mono.Addins, so I Charlie On Fri, Dec 5, 2014 at 5:56 AM, Rob Prouse notifications@github.com wrote:
|
I've posted a spec for this feature at https://github.com/nunit/docs/wiki/Multiple-Asserts-Spec Kindly comment on it here. |
I did a spike and was able to get it to work in an adhoc way by creating a message that included all the failures, with their messages and stack traces. The real solution requires making a number of changes to the how we report assertions and these should be in place first. The main pre-requisite is that TestResult should be capable of holding a list of AssertionResults and all our upstream reporting should be able to deal with that change. I'm marking this issue as pending for now. |
Hey Charlie,
Many thanks for such a wonderful product. Thanks, Shrirang Vaze |
@svaze Thanks for the input. As you point out, this feature is particularly useful for functional testing. We have kept it in the plan for the 3.0 release for exactly that reason. OTOH, since it's less useful for unit testing, which has always been the core of NUnit, we have not yet given it a high priority. The status is pending because of the internal changes needed to implement it, as described in some of the comments above. Allowing a Test to have multiple Results is a fairly big design change and potentially disruptive to the rest of NUnit. We will continue to work on this idea and try to keep it in the 3.0 release, but it's possible it will get pushed to the following release, depending on our resources. It's more important to us to actually have a 3.0 release! The feature involving attachments has never been requested. If you would like to create an issue for it, that would be a welcome contribution. You should provide fairly complete detail on how it would work, how it would be used by tests, etc. Note that saying it should work "like mbUnit" won't really do the job for us. Only a few folks working on the project are familiar with mbUnit. If only those few can understand your request, then it's much less likely to be implemented. Fair enough? |
Hey, I can see the milestone was modified but I'm unsure if that means available as a whole or only partially available as the [MultipleAssert] attribute also does not seem to be available. Would you be able to advise if this feature is available or if the multiple assert feature is just not fully implemented yet? Thanks. |
As indicated on #391, the feature has been postponed until NUnit 3.2. Assert.Multiple is a stub method which seems to have been committed On Thu, Nov 12, 2015 at 1:06 AM, shortstacked notifications@github.com
|
Devil in the details for sure! As well as in the mind of the user who has to understand what's happening! I commented separately on #1737. Now let's all get back to how this will look to runners!!! |
As you see, I made this into an Epic. (If you don't see, you have to install ZenHub.) I think #1743 is the key item requiring some decisions in order to move ahead. |
IMHO there is no need to use an extra Attribute in order to mark a test as a multi-assert test. It's unflexible. Why not allow common Asserts along with new classes like SingleAssert? SingleAssert objects could be added to a MultiAssert object. Like this, common assert can lead to assertions as usual while several single-asserts, added to a multi-assert object fulfills the multi-Assertion Feature. |
@yetibrain I agree that there's no need... but it's part of the syntax that somebody requested because it happens to match what they use in mbUnit. I see it as a marginally convenient shorthand that equates to wrapping all the code in an Assert.Multiple block. When I made this issue into an Epic, I didn't create a separate issue for designing the syntax because I thought it had been settled for more than a year. It sounds like you would like to discuss an alternative syntax, as has also been proposed by @jcansdale in #1737. Do we need to make a new issue for the syntax? Right now, I'm focused on what the result file will look like (#1743) but I don't think more discussion of the syntax would hurt us and it's pretty much independent of the shape of the output. |
After a great deal of discussion under issue #1802, now closed, the spec on the wiki has been updated: Implementation will proceed under this Epic as soon as the other sub-issues are resolved. |
Cool! It turns out you can add issues from multiple repositories to an epic! |
I think we have one loose end in the implementation. I'll lay it out here and we can decide how to proceed, creating another sub-issue if necessary. The spec describes actions to take on early termination. See https://github.com/nunit/docs/wiki/Multiple-Asserts-Spec#early-termination In each case, if there are pending failures, we are supposed to give a special message. This is not yet implemented. It's not clear whether we should list the failures in some or all of these cases. @nunit/core-team Should we implement messages as described? Should we list info about the pending failures? |
I'm going ahead and creating a separate issue, but I'm still looking for comments from @nunit/core-team and @nunit/contributors |
I vote for implementing the special message for pending failures and listing it for all of the cases. |
I created issue #1907 to handle this in nunitlite and nunit/nunit-console#136 for the console runner. |
Closing the epic itself, now that all the issues are complete. |
Using new adapter related settings from runsettings of testplatform
Uh oh!
There was an error while loading. Please reload this page.
May I ask if there is a plan to have something similar to MbUnit's Multiple Assertions capability?
This might provide some insight:
https://code.google.com/p/mb-unit/source/browse/trunk/v3/src/MbUnit/MbUnit/Framework/Assert.cs?r=1570#282
Evaluates a block of code that contains multiple related assertions.
While the action delegate runs, the behavior of assertions is change such that
failures are captured but do not cause a
to be throw. When the delegate returns, the previous assertion failure behavior
is restored and any captured assertion failures are reported. The net effect
of this change is that the test can continue to run even after an assertion failure
occurs which can help to provide more information about the problem.
A multiple assertion block is useful for verifying the state of a single
component with many parts that require several assertions to check.
This feature can accelerate debugging because more diagnostic information
become available at once.
Also:
https://code.google.com/p/mb-unit/source/browse/trunk/v3/src/MbUnit/MbUnit/Framework/MultipleAssertsAttribute.cs?r=1570
Runs the test as if it were surrounded by so that
multiple assertion failures within the test are tolerated.
When an assertion failure occurs, it is reported but the test is allowed to proceed
until it completes or throws an unhandled exception. When the test finishes, it will
still be marked as failed, as usual.
Partial specs as entered below by @CharliePoole
There are a number of things needed here and I guess it's time to make a list! I may end up breaking some of these out into separate issues, but for the moment let's just stick with bullet points.
<results>
element containing one or more<result>
elements and superseding some existing elements.The preliminary part of this, supporting multiple results per test, will actually be useful for three different features we would like to have:
If anyone wants to pull out a part of this and work on it, let me know.
The text was updated successfully, but these errors were encountered: