[This was originally posted at
http://timstall.dotnetdevelopersjournal.com/getting_categories_for_mstest_just_like_nunit.htm]
Short answer: check out: http://www.codeplex.com/testlistgenerator.
Long answer: I previously discussed Automating Code Coverage from the Command Line. Another way to buff up your unit tests is to add categories to them. For example, suppose you had several long-wrong tests (perhaps unit testing database procedures), and you wanted the ability to run them separately, using categories, from the command line.
The free, 6-year old, open-source NUnit has category attributes, for which you can filter tests easily by. For a variety of reasons, MSTest - the core testing component of Microsoft's flagship development product, after 2 releases (2005 and 2008) still does not have these. I've had the chance to ask to ask people at MSDN events about these, and I've heard a lot of "reasons":
Proposal for why MSTest does not need categories: | Problem with that: |
Just put all those tests in a separate DLL | - This does not handle putting a single test into two categories. Also, it's not feasible, often the tests we want to categorize cannot be so easily isolated.
|
Just add the description tag to them and then sort by description in the VS GUI | - You still cannot filter desc from the command line - it requires running in a GUI
- This fails because it does an exact string comparison instead of a substring search. If you have Description("cat1, cat2"), and Description("cat1") - you cannot just filter by "cat1" and get both tests, it would exclude the first because "cat1" does not match "cat1, cat2".
- Conceptually, you shouldn't need to put "codes" in a "description" field. Descriptions imply verbose alpha-numeric text, not a lookup code that you can filter by.
|
Just filter by any of MSTest's advanced filter GUI features - like class or namespace. | - This requires opening the GUI, but we need to run from the command line.
- Sometimes the tests we need to filter by span across the standard MSTest groups.
|
Just use MSTest test lists | - This is only available for more advanced version of VS.
- This is hard to maintain. It requires you continually update a global test file (which always becomes a maintenance problem), as opposed to applying the attributes to each test individually.
|
Well, you shouldn't really need categories, just run all your unit tests every time. | - Of course your automated builds should eventually run all unit tests, but it's a big time-saver for a developer to occasionally just run a small subset of those.
|
So, if you want to easily get the equivalent of NUnit categories for your MSTest suite, check out http://www.codeplex.com/testlistgenerator.
No comments:
Post a Comment