When I'm testing a void method there is nothing to assert.For example a CreateSomething method. I know I could call in the test method an other method like FindSomething,but anyway, if there is (in the create method) an error it will show up. So it's a good practice to call an assertion in every method or i'm fine sometimes without an assertion ?
I should definitely use only one assert in test method! Using many asserts may be the code smell that you are testing more than one thing. Moreover, there is a chance that somebody can add new assert into your test instead of writing another one.
“One assertion per test” is a wise rule to keep in mind, because it helps you have tests that fail for a specific reason, and drives you to focus on a specific behavior at a time.
Multiple asserts are good if you are testing more than one property of an object simultaneously. This could happen because you have two or more properties on an object that are related. You should use multiple asserts in this case so that all the tests on that object fail if any one of them fails.
Answer : It is not good to have multiple asserts in a single unit test case. It's better to use only one assert statement in single unit test case.
But your test code should do at least one of these:
So it's values, actions and errors that you should be checking. Sometimes just one of these, sometimes you can't do it without a combination.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With