CI Tools and Best Practices in the Cloud

Continuous Integration

Subscribe to Continuous Integration: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get Continuous Integration: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Continuous Integration Authors: Yeshim Deniz, Mehdi Daoudi, Elizabeth White, Liz McMillan, Pat Romanski

Related Topics: Continuous Integration

Continuous Integration: Article

Automatic Integration with CruiseControl.NET, NAnt, and NUnit

How to implement the the concept of regression testing during implementation

What Is a Successful Build?
It is worth noting again that a successful build is not just compilation and linkage of the source code without errors; it is also the successful execution, without failure, of unit tests. Let's try an exercise with the BaseRobot class where we make a modification to the source that while successfully compiles, actually breaks the build (source code for this article is available by viewing source.html). Our BaseRobot has the ability to turn left and right and to move forward, and nothing more. Let's provide it with the ability to move backwards as well.

Following the tenets of Test Driven Development (TDD), we need to write our test first. It will go in the BaseRobotTest class and look something like this:


[Test]
public void TestMoveBackward()
{
Robot.MoveBackward();
Assert.AreEqual(Robot.XCoordinate, 0);
Assert.AreEqual(Robot.YCoordinate, -1);
Robot.TurnLeft();
Robot.MoveBackward();
Assert.AreEqual(Robot.XCoordinate, 1);
Assert.AreEqual(Robot.YCoordinate, -1);
Robot.TurnLeft();
Robot.MoveBackward();
Assert.AreEqual(Robot.XCoordinate, 1);
Assert.AreEqual(Robot.YCoordinate, 0);
Robot.TurnLeft();
Robot.MoveBackward();
Assert.AreEqual(Robot.XCoordinate, 0);
Assert.AreEqual(Robot.YCoordinate, 0);
}
When we compile the solution it fails because we have not yet implemented the MoveBackward() method. Our next step is to write code that will pass compilation:

public void MoveBackward()
{
}
The last step is to write the code that will make the test pass:

public void MoveBackward()
{
switch(_Direction)
{
case DIRECTION.North:
_YCoordinate++;
break;
case DIRECTION.East:
_XCoordinate++;
break;
case DIRECTION.South:
_YCoordinate--;
break;
default:
_XCoordinate--;
break;
}
}
My code compiles fine, but when I was implementing the logic for my robot I made an error and my coordinates are incremented and decremented incorrectly. I also became careless and decided to check back in my code without determining if my test runs properly. The continuous integration server recognized the modification to source and started a new build. Of course it failed unit testing and promptly reported a broken build (see Figure 3).

The continuous integration server has done its job! Since I received instant feedback I not only know I was the developer who broke the build, but I also know what changed and can more easily find the issue in order to correct it. Here is the new implementation that compiles and passes the unit testing:


public void MoveBackward()
{
switch(_Direction)
{
case DIRECTION.North:
_YCoordinate--;
break;
case DIRECTION.East:
_XCoordinate--;
break;
case DIRECTION.South:
_YCoordinate++;
break;
default:
_XCoordinate++;
break;
}
}
This time I ran the tests to ensure they passed before checking in my source files. Now when I check in the source, CruiseControl.NET reports a successful build! (Note: TDD is a very in-depth subject and this article cannot possibly do it justice. A great resource on the subject is the book Test Driven Development in Microsoft.NET by James W. Newkirk and Alexei A. Vorontsov, available from Microsoft Press.)

Summary
One last thing to mention is the CruiseControl.NET monitor that runs on the desktop as a Windows tray icon. It can be pointed to the build server and provides instant feedback to team members about the result of a build or the state of the server itself. Hopefully this article has given you the basics for getting started with your own continuous integration process quickly and easily. Once you start and maintain a continuous integration development environment, you will wonder how you used to develop without one.

More Stories By Donald King

Donald King is the founder of Webforge Software, a Web-applications development and consulting firm located in Topeka, Kansas. Don has extensive experience in object-oriented technologies and Web-based application development.

Comments (5) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Rick 12/12/05 05:25:42 PM EST

Too topical... where's the beef?

.NET News Desk 11/12/05 06:19:27 PM EST

Automatic Integration with CruiseControl.NET, NAnt, and NUnit. One of the most important and yet overlooked aspects of a software development project is the concept of regression testing during implementation. Regression testing is the practice of running tests for previously tested code following modification to ensure that faults have not been introduced or uncovered as a result of the changes made. In this article I will outline the need for continuous integration, automated builds, and testing, which support the tenets of regression testing and provide automation for the process. I will also introduce some of the free open source tools that can be used to effectively employ a continuous integration process, and we'll take a look at a scenario that demonstrates their use.

.NET News Desk 11/12/05 06:19:13 PM EST

Automatic Integration with CruiseControl.NET, NAnt, and NUnit. One of the most important and yet overlooked aspects of a software development project is the concept of regression testing during implementation. Regression testing is the practice of running tests for previously tested code following modification to ensure that faults have not been introduced or uncovered as a result of the changes made. In this article I will outline the need for continuous integration, automated builds, and testing, which support the tenets of regression testing and provide automation for the process. I will also introduce some of the free open source tools that can be used to effectively employ a continuous integration process, and we'll take a look at a scenario that demonstrates their use.

SYS-CON Australia News Desk 11/12/05 06:05:16 PM EST

Automatic Integration with CruiseControl.NET, NAnt, and NUnit. One of the most important and yet overlooked aspects of a software development project is the concept of regression testing during implementation. Regression testing is the practice of running tests for previously tested code following modification to ensure that faults have not been introduced or uncovered as a result of the changes made. In this article I will outline the need for continuous integration, automated builds, and testing, which support the tenets of regression testing and provide automation for the process. I will also introduce some of the free open source tools that can be used to effectively employ a continuous integration process, and we'll take a look at a scenario that demonstrates their use.

.NET News Desk 11/12/05 05:51:11 PM EST

Automatic Integration with CruiseControl.NET, NAnt, and NUnit. One of the most important and yet overlooked aspects of a software development project is the concept of regression testing during implementation. Regression testing is the practice of running tests for previously tested code following modification to ensure that faults have not been introduced or uncovered as a result of the changes made. In this article I will outline the need for continuous integration, automated builds, and testing, which support the tenets of regression testing and provide automation for the process. I will also introduce some of the free open source tools that can be used to effectively employ a continuous integration process, and we'll take a look at a scenario that demonstrates their use.