Test-Driven Development with Databases, what is the best way to doit?

Discussion in 'ASP .Net' started by Sasha, Mar 2, 2005.

  1. Sasha

    Sasha Guest

    Hi everybody,

    I am starting a new ASP.NET/SQL Server project and this time I want to
    do it through Test-Driven Development (TDD). The problem that I ran into
    is this: How do you test data access logic with a database in the
    backend? I do not want to use mock objects because if the schema changes
    I will miss those errors.

    If you are using TDD to test data access code, please post the
    description of your setup or some pointers and suggestions.

    Thank you very much for your help!

    Sasha
     
    Sasha, Mar 2, 2005
    #1
    1. Advertising

  2. Re: Test-Driven Development with Databases, what is the best way to do it?

    Without Mock objects, testing the DAL is challenging. One way I would do it
    is:

    1. Unit test your database code separately -- using something like
    T-SQLUnit.
    2. Create a "baseline" database to test your DAL objects
    3. Write unit-tests for your DAL objects. Make sure that after each test,
    the database returns to the original state -- using TearDown.

    The most challenging parts I found were if you were using identity columns,
    and want to unit test object IDs.

    Hope that helps, but if you find a better answer please post it to the
    newsgroup.

    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Sasha" <> wrote in message
    news:...
    > Hi everybody,
    >
    > I am starting a new ASP.NET/SQL Server project and this time I want to
    > do it through Test-Driven Development (TDD). The problem that I ran into
    > is this: How do you test data access logic with a database in the
    > backend? I do not want to use mock objects because if the schema changes
    > I will miss those errors.
    >
    > If you are using TDD to test data access code, please post the
    > description of your setup or some pointers and suggestions.
    >
    > Thank you very much for your help!
    >
    > Sasha
     
    Manohar Kamath, Mar 2, 2005
    #2
    1. Advertising

  3. Sasha

    bruce barker Guest

    Re: Test-Driven Development with Databases, what is the best way to do it?

    look at mbunit

    -- bruce (sqlwork.com)

    "Sasha" <> wrote in message
    news:...
    | Hi everybody,
    |
    | I am starting a new ASP.NET/SQL Server project and this time I want to
    | do it through Test-Driven Development (TDD). The problem that I ran into
    | is this: How do you test data access logic with a database in the
    | backend? I do not want to use mock objects because if the schema changes
    | I will miss those errors.
    |
    | If you are using TDD to test data access code, please post the
    | description of your setup or some pointers and suggestions.
    |
    | Thank you very much for your help!
    |
    | Sasha
     
    bruce barker, Mar 2, 2005
    #3
  4. Sasha

    Scott Allen Guest

    Re: Test-Driven Development with Databases, what is the best way to do it?

    Hi Sasha:

    Two thoughts to consider:

    Depending on your design you could use an O/R mapper or code
    generation tool to spit out code. There are advantages and
    disadvantages to this approach, of course, but one of the advantages
    is you'll have compile errors if the upper layer code is not keeping
    up with the schema changes.

    Unit testing code that needs access to the database can be tricky,
    using mock objects doesn't solve all the problems of course but it can
    remove some dependencies and make testing easier. One approach I've
    seen used is to test against the real db, but wrap your test methods
    with enterprise transactions, there is a discussion here:
    http://weblogs.asp.net/rosherove/articles/dbunittesting.aspx

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/


    On Wed, 02 Mar 2005 11:29:04 -0800, Sasha <> wrote:

    >Hi everybody,
    >
    >I am starting a new ASP.NET/SQL Server project and this time I want to
    >do it through Test-Driven Development (TDD). The problem that I ran into
    >is this: How do you test data access logic with a database in the
    >backend? I do not want to use mock objects because if the schema changes
    >I will miss those errors.
    >
    >If you are using TDD to test data access code, please post the
    >description of your setup or some pointers and suggestions.
    >
    >Thank you very much for your help!
    >
    >Sasha
     
    Scott Allen, Mar 2, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yan-Hong Huang[MSFT]
    Replies:
    0
    Views:
    419
    Yan-Hong Huang[MSFT]
    Oct 15, 2003
  2. Michael P Smith

    Test-driven Development in C#

    Michael P Smith, Apr 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    654
    Dan Pop
    Apr 26, 2004
  3. Steven D'Aprano

    Test-driven development of random algorithms

    Steven D'Aprano, Nov 14, 2006, in forum: Python
    Replies:
    2
    Views:
    276
    Ben Finney
    Nov 14, 2006
  4. Shaguf
    Replies:
    0
    Views:
    825
    Shaguf
    Nov 28, 2008
  5. bob
    Replies:
    3
    Views:
    194
Loading...

Share This Page