Are there soft assertions in NUnit?

Is there such a thing as soft assertions in NUnit? If so, how should I use it?

Background and details of what I mean by "soft statements":

In a set of acceptance tests, I want to check that the form is filled out correctly. I am currently doing this with the following flow step:

Then The new note form is filled out as follows
         | Label       | Value    |
         | First Name  | John     |
         | Last name   | Skeet    |
         | Title       | Cool Kat |

      

which is implemented something like this:

[Then(@"The new note form is filled out as follows")]
public void ThenTheNewNoteFormIsFilledOutAsFollows(Table table)
{
    foreach (var row in table.Rows)
    {
        var name = row["Label"];
        var value = row["Value"];

        switch (name)
        {
            case "First Name":
                // Page is part of our automation framework - Page.FirstName is 
                // simply an abstraction over getting the value of the 
                // <input name="FirstName" />
                Assert.That(Page.FirstName, Is.EqualTo(value), 
                            "Incorrect first name: Expected {0}, was {1}", 
                            value, Page.FirstName);
                continue;
            case "Last Name":
                Assert.That(Page.LastName, Is.EqualTo(value), 
                            "Incorrect first name: Expected {0}, was {1}", 
                            value, Page.LastName);
                continue;
            // similar cases for the other properties
        }
    }
}

      

This works because it gives us the correct test results (pass / fail) and error messages that show what went wrong. However, because test execution is aborted when it Assert

fails, only the first value of the failed form is reported; if, say, the form was empty, then only First Name

the example above would be missing and I would have to rerun the test to see which is Last Name

also missing.

Since these are browser automation tests, the battery life is quite long and it would be nice to get a test failure that reports all invalid form elements, not just the first one.

Is this possible with NUnit?


To readers who want to argue "Don't do this - the unit test should just test one thing":

Yes, I know - but your argument is not valid because it is not a unit test. This is an acceptance test that checks if the entire stack is working. We use NUnit to design and run these tests, but that doesn't make them unit tests.

+3
unit-testing assertions nunit


source to share


No one has answered this question yet

See similar questions:

27
NUnit, can test execution continue after Assert fails?

or similar:

705
How can I use Assert to check that an exception has been thrown?
371
NUnit vs. MbUnit vs. MSTest vs. xUnit.net
369
Best practice for Python
70
Continuation in Python unittest when assertion fails
4
NUnit tests are running on the build server but report incorrect counting of test results
4
What makes a good error message for testunit or other nunit style frameworks?
3
How to make NUnit check all values ​​in a list, not just the first failure
0
Coercing reasonable multiple assertions with integration tests
0
How do I get expected and actual NUnit results even if the tests pass?
0
Checking count in unit test using free assertions and Nunit



All Articles
Loading...
X
Show
Funny
Dev
Pics