Multiple Asserts in a Unit Test

Posted by whatispunk on Stack Overflow See other posts from Stack Overflow or by whatispunk
Published on 2010-05-20T23:59:21Z Indexed on 2010/05/21 0:00 UTC
Read the original article Hit count: 218

Filed under:
|
|

I've just finished reading Roy Osherove's "The Art of Unit Testing" and I am trying to adhere to the best practices he lays out in the book. One of those best practices is to not use multiple asserts in a test method. The reason for this rule is fairly clear to me, but it makes me wonder...

If I have a method like:

public Foo MakeFoo(int x, int y, int z)
{
     Foo f = new Foo();
     f.X = x;
     f.Y = y;
     f.Z = z;

     return f;
}

Must I really write individual unit tests to assert each separate property of Foo is initialized with the supplied value? Is it really all that uncommon to use multiple asserts in a test method?

FYI: I am using MSTest.

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about assert