.NET Framework
XNA
Visual Studio
ASP.NET
C#
MSSQL
VB.NET
Articles > Visual Studio > Continuous Integration and Test Driven Development

Continuous Integration and Test Driven Development

Introduction to Test Driven Development  and Continuous Integration

Mankato .NET User Group, August 26, 2008

Loren Halvorson

Test Driven Development

Write your unit tests first

  • “Red-Green-Refactor”
  • Tests go into source control along with your code
Benefits
  • Better designs. Outside-in.
  • Testability is not an afterthought
  • Tests provide a “safety net” that give you confidence to refactor
  • Tests can serve as developer documentation

Tools Used

  • TestDriven.NET, NUnit, NCover, NCoverExplorer, Visual Studio Team System

--DEMO--

Sometimes you can’t write unit tests first. Then write them last, just write them!

  • Tests to validate a defect is fixed
  • Test to learn code you’ve inherited
Tests must be run automatically and frequently
  • If you are never running your tests, you wasted your time writing them

Continuous Integration

Imagine you are the only developer working on a system, and you can only compile once a day at midnight

  • You would spend much of the next morning fixing the issues from the day before

Now what happens when several developers are working on a system?

  • It gets much harder to find the issues

This equates to lost productivity
Broken builds are expensive
The solution is simple

  • Build more often

Continuous integration collects everyone’s changes together and performs an integrated build and unit test as often as practically possible

  • “Daily builds are for wimps: XP teams build multiple times per day.”

Continuous Integration Benefits

  • Being notified of a problem as soon after the introduction of the problem greatly simplifies troubleshooting
  • You don’t spend as much time tracking down cause of problems
  • Because unit tests are being run as part of every build, runtime logic problems are also detected, not just syntax problems
  • "Keep it green" psychological effect on team, especially when you use some type of visible build indicator like centrally located display, Ambient Orb, Stoplight or Lava Lamps etc.
  • Build automation necessary to enable continuous integration has a host of benefits such as: robustness, repeatability, history, additional quality metrics, confidence to re-factor

CruiseControl.NET

  • Open source build server for enabling continuous integration builds
  • Runs builds whenever developers check in code and on nightly schedules
  • Reports results via e-mail and web dashboard
  • Automatically runs unit tests, code analysis, documentation generation, deployments, smoke tests and more

Other tools that integrate well with CruiseControl.NET

  • Build tools
    • NAnt, MSBuild, Powershell, Batch files, VS…
  • Quality / testing tools
    • NUnit, NCover, FxCop, SWExplorerAutomation, NDepend, Simian, custom…
  • Documentation generation tools
    • Sandcastle
  • Installer
    • WiX
  • Some projects automate entire process
    • Build ? Test ? Package ? Deploy ? Smoke
  • -- DEMO --

Other products that do continuous integration

  • CI Factory (free)
  • Team City ($)
  • Visual Studio Team System 2008 with Team Foundation Server 2008 ($$)
  • More..
     

This web site uses Kentico CMS, the content management system for ASP.NET developers.