locked
Test Driven Development for WebServices (Using VS 2005 Team Edition) RRS feed

  • Question

  •  Hi Everyone,
     Currently I am doing Test Driven Development in C# . Here I am using the TRANSACTION APPROACH to maintain constant data for each test case.  So what I am doing now is

    // This is the pseudocode

    OPEN CONNECTION GLOBAL TO ALL UNIT TESTS and Open transaction for each unit test and rollback the same after each unit test.

    Begin C# Transaction (ADO.Net Transaction on the SqlConnection Object)
     {
        UnitTest 1  --> using Visual Studio 2005 Team Edition for Software Developers
    }
    RollBack C# Transaction

    ......................................................

    Begin C# Transaction (ADO.Net Transaction on the SqlConnection Object)
     {
        UnitTest 2  -->
    using Visual Studio 2005 Team Edition for Software Developers
    }
    RollBack C# Transaction

    etc..

    Now for doing TDD Approach for WebServices, I wanted to know how it can be accomplished. Would it be wise to open a transaction for each WebService's  WebMethod and rollback transaction at the end of that particular unit test.  If anyone has implemented TDD Approach for WebServices, can you post some links here or some code which shows how to implement the same.

    Thanks in  Advance.
    Tuesday, January 6, 2009 3:27 PM

All replies

  • In the projects I've worked on we treated the  web service as a facade for access only.  All the funcionality was in components the web methods used.  As these components had thier own tests, there was no need to test the web methods as you are suggesting.

     

    If you want to use the transactional approach in your data access components you need to ensure each test runs in isolation so wrapping all data changes in a transaction is correct.

     

    You can use <classinitialise> and <classcleanup> attributes to mark methods that execute before and after each test.  You can then begin and rollback transactions is these.

     

    However, as this approach leads to slow test suites I prefer using a mocking framework to test data access functionality.

     

    hope this helps

     

    Wednesday, January 7, 2009 3:05 PM
  • Hi,

    I recently came across something which can handle transactions over webservice, which is nothing but enclosing the WebService inside a COM+ transaction using System.EnterpriseServices. The Below link talks about the same.

    http://weblogs.asp.net/rosherove/articles/DbUnitTesting.aspx

    But in this approach, I cannot put a breakpoint in my visual studio  2005 . I believe this is because the entire asp.net webservices is encompassed inside a COM+ transaction for which we cannot put a breakpoint using visual studio 2005.

    I am using Visual Studio 2005 Team Edition for Software Developers and my Database is SQL 2005 .
    Please let me know your comments on the same. I am still trying to implement this approach . This article was basically for NUnit..but I believe can be modified to adapt to the Visual Studio 2005 Unit Testing

     

    Friday, January 9, 2009 11:02 AM
  • Yes, this is the same technique described in my previous post - NUnit Teardown is equivalent to the [TestCleanup] attribute in the MS testing framework.

     

    Our code is under test before we get to the web service layer.  In our system the web service has no additional functionality and is merely used as the endpoint for the client call.

     

    sorry I can't be of more help

     

    Friday, January 9, 2009 11:18 AM