This post originated from an RSS feed registered with .NET Buzz
by Maruis Marais.
Original Post: VS2005 Unit Testing Problems
Feed Title: exceptionz
Feed URL: http://feeds.feedburner.com/Exceptionz
Feed Description: I am an XP, TDD, OO and .NET enthusiast. Things like Design Patterns makes my pulse race, I love learning exciting new things and to share my thoughts and techniques with the world. So join me and together we can explore the awesome world of software development
I've been using VS2005 Team developer on a commercial project for the past 5 months and the amount of issue's Iâve found with things like the Testing framework and some other IDE oddities, has made me seriously conceder returning to NUnit as a testing framework again. I still feel NUnit is superior as a framework, it might not have the data driven test or the whiz-bang CollectionAssert objects, but for doing TDD it is still the best.
Today my VS IDE stopped executing the test for some reason. When you run the test inside the test view window, the IDE display the test result window with the test appearing as pending. Then suddenly the tests turn into aborted. Why? Beats me... I'll try to fix the problem tomorrow.
So what problems did I find with the VS2005 Testing framework:
It doesn't handle inheritance at all - here is a code snippet explaining what I mean:
James Newkirk used this approach in his book Test-Driven Development in Microsoft .NET to enable you to test Data access code. You create a connection then test the connection is open, then on the derived TransactionTest you create a new transaction and call the InsertDomainObject method that is abstract. On the DomainObjectTest fixture, the insert method is implemented and you save some data to the database. This is inside a transaction, so now you can perform your test. When the test is completed, the TearDown get's called, which will roll the tranaction back, causing the database to return to it's original state.
In this example VS2005 will sqeal with the following message "UTA018: DataAccessLayerTest.DomainObjectTest: Cannot define more than one method with the TestInitialize attribute.". This is a bit of a problem as you normally would structure your tests using standard OO techniques like above. I've got quite few of these inheritance issue examples. So how do we solve this issue? In a very ugly way, here is the code:
You have to explicitly call base.[METHOD] to get the inherited methods to be called. A bit of a problem in that you can't just decorate the methods with the Initialize and Cleanup attributes. Painful....
Here you can find another issue with Assert.AreEqual.