Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I force a unit test to fail if there are no Asserts?

Some programmers in my team sometimes write unit tests which call the method, gets the result but forget to call the proper Assert methods to actually check what's happening.

I was wondering if there is any configuration I can do to force MSTest to fail the test if no verification is done. I remember seeing something like this in DUnit, but could not find it in Visual Studio.

like image 409
Doug Avatar asked Aug 27 '12 20:08

Doug


1 Answers

Check out Test-Lint from Roy Osherove and co. It's static code analysis for test code.

I tried it out once when it was out for public alpha/beta.. was pretty well-behaved. However didn't try out this specific need. I don't think MSTest or most unit testing frameworks will guard against this out-of-the-box.

Also aquinas has a valid comment.. Education might work better than inspection-and-the-stick. You may even be able to create a custom rule to catch rogue asserts.. Check the tool out.

From the home page of the tool,

What issues does it detect?
Currently Test Lint finds a set of common problems:
* Missing asserts in your tests

like image 60
Gishu Avatar answered Sep 20 '22 04:09

Gishu