Bugs and Missing Features with Team System Unit Testing: Part I

Here are a couple more examples on the immaturity of the current Team System Unit Testing in "Quality Tools" . Both of these were submitted to the product feedback center, which, unfortunately, only seems to have been catered Towards the pre-release versions of VS.NET. But I still added them anyway, just so that maybe someone looks over at them. Feel free to click on the title links and vote for them if you think they are important enough.
Both of these,BTW, apply to the situation in which you'd like to test than an Exception is indeed thrown from your code when expected.
 

This one is a bug:
While writing a unit test with an "ExpectedException" attribute and also setting the "Message" property on the excpected exception, the test passes even though the exception that was thrown has a different message.
Steps to Reproduce:
 
[TestMethod]
[ExpectedException(typeof(InvalidOperationException),"Some Message")]
public void MyTest()
{
//this test will pass, but it should fail on the exception  message being wrong
throw new InvalidOperationException("Some Other Message");
}
 
How this one went by into the release is a mystery to me. Obviously no onw has ever used this functionality to actually talk about the fact that it's broken (and no one actually tested for it). Bad.
 

Here's the second one - it's a suggestion on a missing feature which should have been there.
Example:
[TestMethod]
[ExpectedException(typeof(Exception),"Some Message")]
public void MyTest()
{
//this test will NOT COMPILE claiming that the attribute requires something that DERIVES from Exception
...
}
 
[TestMethod]
[ExpectedException(typeof(InvalidOperationException),"Some Message")]
public void MyTest()
{
//this test WILL COMPILE
...
}
 
Right now if I want to write a test than expects an exception, I have to make sure that the thrown exception *has* to derive from Exception, and cannot use the Generic Exception object.
In many cases, developers would like to use a generic exception, either because they are not sure what exception the code will throw, or they just want to use the simplest thing that works.
The current situation makes the developer find some other generic exception, against their better judgment.
This is different than the default behavior in NUnit and I'm curious as to why this is so.

Here are some more observations:
 
The Test List Window is not Usable for Test Driven Development:
  • When the tests are running, you get to see a list of *all the tests*. Passing and failing together. If I'm working with Test Driven Development, the last test is usually the one to fail, but that last test is also usually located waaay down then on the bottom of the list, making me scroll to reach it every time. It's be OK if I could at least sort the list based on pass/fail status, but I can't!.
  • Workaround: Use TestDriven.NET. It only shows you the failed tests.
 
  • If a test fails, double clicking on it opens the test failure description dialog page, instead of the failing code. I guess that's OK if that was a regular test, but for unit tests, the default behavior should at least be configurable to jump to the code of the test. Not only that: for an exception, it should put me exactly where the exception occurred (just like double clicking on a call stack line in the output window) . 
  • Workaround: Use TestDriven.NET: it allows clicking on a line of an exception or error in call stack, and it puts you right on that line in the code editor.
 
  • Running the tests does not necessarily invoke the *build* process. so in Test Driven Development, I have to continuously Build (Ctrl-Shift-B), and then run the current test project (Ctrl-Shift-X). Unacceptable, and should at least be configurable.
  • Workaround: Use TestDriven.NET : running tests automatically invokes the build first
 
  • No default hierarchical view of the tests by namespace/class. If you're trying to build an NUnit killer, at least build in the correct UI like NUnit inside the IDE. Right now, if I want to run only some of the test, I have to manually arrange them by class, or namespace, and create my own test lists. That sucks, I'd like a default arrangement that I can use ad-hoc.
  • Workaround: Use the latest version of NUnit GUI. It  allows running Team System Unit Tests these days too. Just point it at your Team System Dll with unit tests and your'e good to go.
Published Wednesday, January 25, 2006 2:22 PM by RoyOsherove

Comments

Wednesday, January 25, 2006 8:06 AM by Jamie Cansdale

# re: Bugs and Missing Features with Team System Unit Testing: Part I

"Some Message" is actualy the assert message if the expection is not thrown. For example:

[ExpectedException(typeof(InvalidOperationException),"Expected InvalidOperationException to be thrown")]
Wednesday, January 25, 2006 8:43 AM by Antony Marcano

# re: Bugs and Missing Features with Team System Unit Testing: Part I

Jamie wrote:

<blockquote>
"Some Message" is actualy the assert message if the expection is not thrown. For example:

[ExpectedException(typeof(InvalidOperationException),"Expected InvalidOperationException to be thrown")]
</blockquote>
------------------

Although this may be true for Team System, isn't the case with NUnit.
Wednesday, January 25, 2006 9:33 AM by Jamie Cansdale

# re: Bugs and Missing Features with Team System Unit Testing: Part I

You prompted me to write a little about VSTT support in TestDriven.NET:

http://weblogs.asp.net/nunitaddin/archive/2006/01/25/436420.aspx
Wednesday, January 25, 2006 10:13 AM by Roy Osherove

# re: Bugs and Missing Features with Team System Unit Testing: Part I

Jamie:
You'd think that, but even if that's the case, that feature does not work (i.e: you don't see that message written anywhere if the test fails...)
Wednesday, January 25, 2006 11:12 PM by David M. Kean

# re: Bugs and Missing Features with Team System Unit Testing: Part I

> they just want to use the simplest thing that works

I would prefer the QA tested for the correct exception, rather than the simplest thing that worked.

Regarding testing the message - you would start having issues with localization if that was the case. I would like the ability to run some sort of RegEx over the exception message.
Friday, January 27, 2006 11:01 AM by Roy Osherove

# re: Bugs and Missing Features with Team System Unit Testing: Part I

David:
The QA is not the one doing Test Driven Development- that's why it's called "Developer Testing".
However, I agree about the localization issues that can arise. There are better ways to check for the message ina multi localized way. My issue was that is the quality tools in VSTS want to be a NUnit killer, they should start out with the basic NUnit features and make them work first.
Saturday, May 27, 2006 1:56 PM by Eduardo Miranda

# re: Bugs and Missing Features with Team System Unit Testing: Part I

I posted a workaround for exception/message problem at MSDN. For me it's working, but I would appreciate some feedbacks

http://lab.msdn.microsoft.com/ProductFeedback/ViewWorkaround.aspx?FeedbackID=FDBK44621#1

Eduardo
Saturday, September 23, 2006 9:20 PM by Community Blogs

# MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

MbUnit is gaining some momentum as one of the nicest unit testing frameworks for .NET out there. I just

Monday, October 02, 2006 4:43 PM by Todd

# re: Bugs and Missing Features with Team System Unit Testing: Part I

Another oversight in TS Unit testing that may cause some hideous bugs is that the Assert class does not override the static Object Equals() method. A developer may write: Assert.Equals(expected, actual); In a unit test expecting that an assertion would be raised and instead it does nothing since Object.Assert() just returns true or false and allowing the unit test to pass. While this code would compile for TS, NUnit & MbUnit, both NUnit and MbUnit override the Assert.Equals() method of object and correctly make your unit test fail with "Assert.Equals should not be used for Assertions"
Thursday, October 19, 2006 2:44 PM by Tom Marsh

# re: Bugs and Missing Features with Team System Unit Testing: Part I

Todd, thanks for pointing out the oversight. I'll file a bug for us to consider matching teh behavior of NUnit and MbUnit for Assert.Equals.
Friday, May 25, 2007 3:26 PM by joeyDotNet

# VS Testing - Annoyance Of The Day

VS Testing - Annoyance Of The Day

Friday, May 25, 2007 3:27 PM by joeyDotNet

# VS Testing - Annoyance Of The Day

This is mostly a rant, so feel free to skip this one. Really. (Most folks are probably already enjoying