Home > .NET, Continuous Integration, Extreme Programming, Test Driven Development > Automation to the rescue (again) for newbie TDDers! (NCover)

Automation to the rescue (again) for newbie TDDers! (NCover)

My current project (which I am very excited about!) is building an internet facing ASP.NET application for a high profile function. It involves building business objects to map to the database and general functions of the system and then mapping those into the UI. And now the fun part … the entire application has been built using TestDrivenDevelopment (TDD)!

The business layer is being developed test first using NUnit and likewise in the ASP.NET UI using NUnitAsp. The rest of the architecture:

  • SourceGear Vault for Source Control
  • Visual Studio .NET 2003
  • DAL – Thycotic.Data
  • Business objects – hand coded (with the help of a custom rolled generator) and using NullableTypes for exposed properties
  • NAnt script for pulling out of Vault, compiling, running NUnit unit tests and pushing successful builds to integration server (running every 30 mins on a scheduled task – CruiseControl.NET doesn’t support Vault yet …)

What is the problem? TDD is new to the other developers and management. This means that occassionally there is a tendency to not test drive and just add a feature (null check, private method, etc) without a failing test. If we were always pair programming this would be less of an issue but our deadline is too tight to lose the estimated 15% additional time required to pair program. We did pair program on really critical areas of the system – base objects, establishingour data access pattern, exception managementand security. However, the areas of missed TDD code are a great risk as they stand the best chance of containing bugs and swallowing developer time (and this has already been experienced on a few occassions).In true XP style we need an automated tool to help us catchany lack of coverage …

Enter NCover!

  • Integrates with our NAnt process (copy the source tree, instrument it, run the unit tests, generate a coverage report)
  • Provides a metric that we can track and makes management happy by giving them numbers to confirm the TDD process (example reportfrom the NCover website)
  • Points us towards the code of least coverage (and greatest risk) to allow us to either delete it (dead code) or write a test for it (not the nicest … but better than not having a test!)
  • It is automated and provides continuous feedback with no intervention required once configured

I am very impressed by NCover. We have looked at the code (which compiled and passed all its unit tests right after the download!) and it is reallyneat. Well done to the developers! It would be nice to know the coverage strategy it is using (it uses a set of regular expressions at the moment to find branches in C# code) … after looking at the instrumented code, it may need a little tweaking to catch all possible execution paths but it is an amazing and very welcome product.

  1. Paul Wilson
    February 22, 2004 at 2:47 pm

    Sounds like a cool project. I’m wondering what Thycotic.Data really added though, since its pretty easy to code against the data interfaces already — without the late binding performance hit! Anyhow, it does sound very cool to actually get the opportunity to do software right for once.

  2. Steven Smith
    February 22, 2004 at 4:12 pm

    Hmm, apparently it also requires eclipse (at least in the default nant script), at c:\tools\eclipse3M6\…\.

    So much for building on the first try. Looks pretty cool, though – definitely going to have to get it working.

  3. Steven Smith
    February 22, 2004 at 4:27 pm

    Ah, figured it out. The expectedCoverage.xml file that comes with the 0.7 download has those c:\tools\eclipse paths in it. Remove that and run
    nant selfbuild

    instead of just ‘nant’ or ‘nant build’ and it works (42.86% coverage out of the box, it says).

    Now to get it running on one of my projects…

  4. Jonathan Cogley
    February 22, 2004 at 10:25 pm

    I never said “build” 🙂

    I said compiled and passed all its tests … I was using the VS.NET IDE because I was looking at the code to see how it works.

  5. Jonathan Cogley
    February 22, 2004 at 10:47 pm

    Paul,

    There are some other benefits to using Thycotic.Data. It provides the translation of OleDb style parameters (“?”) across .NET providers. This makes SQL queries in code easier and safer (no SQL injection) …

    SELECT * FROM abc where x=? AND y=?

    data.AddParameter(“x”, DbType.Int32, 2);

    Sure, you could do this using the parameter for the platform but then your SQL is database specific (:, @, etc). Or you could use sprocs but then it can be harder to manage all your sprocs (for simple SQL) across a team.

    There is also no way to create an adapter from the interfaces. Thycotic.Data uses some code from Steve Smith to create a DataTable from a DataReader therefore removing the need for an adapter – Steve’s code is probably similar to the code in the framework for the adapter! 🙂
    Another benefit is that the API is simpler.

    For example:

    using (DataAccessor data = new DataAccessor()) {
    data.ConnectionName = “nGallery”;
    data.CommandText = “SELECT * FROM abc WHERE x=?”;
    data.AddParameter(“x”, DbType.Int32, 1);
    DataTable table = data.ExecuteDataTable();
    }

    The difference in performance due to late binding seems to be quite minimal (6-10% slower). I did some testing for a presentation last year at the Pgh.NET UG.
    http://www.thycotic.com/presentation_latebind_slides.html

  6. http://
    February 23, 2004 at 5:17 pm

    I’m interested in hearing more about your experiences with Vault, nAnt, nUnit and CruiseControl.NET.

    This is exactly the setup that I am considering for future projects. At the moment, I’m working on a one-man project, so I’m building with VS.NET. However, I want to set up CruiseControl and nAnt for all future (group) projects as well as moving to Vault (I’ve crossed the line with VSS).

    However, I was a little concerned about the lack of Vault intergration with nAnt and CC.NET. How did you find the integration issues? Are your scripts complicated?

    Do you know when CruiseControl may or may not be integrated with Vault? I know that some work has been done to create nAnt tasks for Vault. Any experience?

  7. Jonathan Cogley
    February 24, 2004 at 3:42 pm

    Johnny,

    We are using the commandline Vault exe called by a NAnt task.

    <exec
    program=”${scc.program}”
    commandline=”-user ${scc.user} -password ${scc.password} -host ${scc.host} -repository ${scc.database} get $/src/xxx/assemblies -destpath ${build.dir}/src/assemblies -nosgvaultfolders”
    failonerror=”true”
    />

    It seems to work very well.

    I have not played with CC.NET since it doesn’t support Vault and I don’t know when it will.
    We are currently using a scheduled task although it would be nice to monitor the repository … although I am not too sure how it would work with frequent checkins since our build process takes around 10 mins (our NUnitAsp tests are slow).

    I tried the Vault tasks for NAnt but couldn’t get them to compile … I think you need the Vault SDK. I posted to ask for a binary but haven’t heard anything.
    http://weblogs.asp.net/wallen/archive/2003/09/11/27130.aspx

    Hope that helps.

  8. http://
    February 24, 2004 at 4:10 pm

    Thanks Jonathan.

    Looks like there are some folks working on integrating Draco.NET with Vault…

    http://support.sourcegear.com/viewtopic.php?t=172

    … so I think I’ll probably look there rather than at CC.NET.

  9. Wayne Allen
    March 10, 2004 at 7:11 pm
  10. Christian Romney
    April 7, 2004 at 10:39 pm

    Shoot,
    CruiseControl.NET is open-source, why don’t a few of us just write the darn Vault integration? Takers?

  11. http://
    June 2, 2004 at 9:59 am

    Ryan Duffield added support for SourceGear Vault to CCNet a few days ago, see doc here : http://confluence.public.thoughtworks.org/display/CCNET/Vault

    Also, for those who didn’t try it already, check out SubVersion (free, open source, doesn’t required SqlServer to work, and integrates well with CCNet, i’m using it successfully for a remote 6 persons project, even in beta)

    http://subversion.tigris.org
    http://tortoisesvn.tigris.org (client tool)

  12. http://
    June 2, 2004 at 10:00 am

    Additional disclaimer : I have not tested CCNet + Vault myself 😉

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: