Closed
Description
The consensus among the community appears to be that each test should have but one logical assertion.
If a developer wants to test that a controller returns a model of the correct type explicitly, they must also test that a view with a particular name is rendered - that's two logical assertions.
[Test]
public void Index_ReturnsCorrectModelType()
{
repository
.Setup(repo => repo.All())
.Returns(PostsMother.CreateEmptyPosts());
controller
.WithCallTo(c => c.Index(1))
.ShouldRenderDefaultView()
.WithModel<PagedList<Post>>();
}
I suspect that this kind of test goes against your philosophy but I am going to bring it up for discussion anyway.
Links:
- http://osherove.com/blog/2005/4/14/try-to-avoid-multiple-asserts-in-a-single-unit-test.html
- http://stackoverflow.com/questions/2430429/are-multiple-asserts-bad-in-a-unit-test-even-if-chaining
- https://github.com/ploeh/Booking/blob/1ccdcc61b699b80f1be0ee5a87c7981d5baace2d/BookingWebModel.UnitTest/HomeControllerTests.cs#L30
Metadata
Metadata
Assignees
Labels
No labels