The Artima Developer Community
Sponsored Link

.NET Buzz Forum
VS2005 Unit Testing Problems

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Maruis Marais

Posts: 290
Nickname: maruis
Registered: Aug, 2005

Ruby rocks, what else can I say...
VS2005 Unit Testing Problems Posted: Mar 27, 2006 3:29 AM
Reply to this message Reply

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
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Maruis Marais
Latest Posts From exceptionz

Advertisement

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:

   20     [TestClass]

   21     public abstract class ConnectionTest

   22     {

   23         [TestInitialize]

   24         public void SetupConnection()

   25         {

   26         }

   27 

   28         [TestMethod]

   29         public void TestConnectionOpen()

   30         {

   31         }

   32     }

   33     [TestClass]

   34     public abstract class TransactionTest : ConnectionTest

   35     {

   36         [TestInitialize]

   37         public void BeginTransaction()

   38         {

   39         }

   40 

   41         public abstract void InsertDomainData();

   42 

   43         [TestCleanup]

   44         public void RollbackTransaction()

   45         {

   46 

   47         }

   48     }

   49     [TestClass]

   50     public class DomainObjectTest : TransactionTest

   51     {

   52         [TestInitialize]

   53         public void Setup()

   54         {

   55         }

   56         public override void InsertDomainData()

   57         {

   58         }

   59         [TestCleanup]

   60         public void TearDown()

   61         {

   62         }

   63         [TestMethod]

   64         public void Test()

   65         {

   66             Assert.IsTrue( true );

   67         }

   68     }

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:

   27     [TestClass]

   28     public abstract class ConnectionTest

   29     {

   30         public void SetupConnection()

   31         {

   32         }

   33         [TestMethod]

   34         public void TestConnectionOpen()

   35         {

   36         }

   37     }

   38     [TestClass]

   39     public abstract class TransactionTest : ConnectionTest

   40     {

   41         public void BeginTransaction()

   42         {

   43             base.SetupConnection();

   44         }

   45         public abstract void InsertDomainData();

   46 

   47         public void RollbackTransaction()

   48         {

   49 

   50         }

   51     }

   52     [TestClass]

   53     public class DomainObjectTest : TransactionTest

   54     {

   55         [TestInitialize]

   56         public void Setup()

   57         {

   58             base.BeginTransaction();

   59         }

   60         public override void InsertDomainData()

   61         {

   62         }

   63         [TestCleanup]

   64         public void TearDown()

   65         {

   66             base.RollbackTransaction();

   67         }

   68         [TestMethod]

   69         public void Test()

   70         {

   71             Assert.IsTrue( true );

   72         }

   73     }

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.

Read: VS2005 Unit Testing Problems

Topic: WPF: Using controls as content Previous Topic   Next Topic Topic: Welcome Karl Seguin

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use