Library tutorials & articles
Test-Driven Development in .NET
- Introduction & Unit Tests
- The NUnit Testing Framework
- Running Your Tests & Doing TDD
- Using Mock Objects - DotNetMock
- Conclusion
Introduction & Unit Tests
Introduction
Although developers have been unit testing their code for years, it was typically performed after the code was designed and written. As a great number of developers can attest, writing tests after the fact is difficult to do and often gets omitted when time runs out. Test-driven development (TDD) attempts to resolve this problem and produce higher quality, well-tested code by putting the cart before the horse and writing the tests before we write the code. One of the core practices of Extreme Programming (XP), TDD is acquiring a strong following in the Java community, but very little has been written about doing it in .NET.
What Are Unit Tests?
According to Ron Jeffries, Unit Tests are "programs written to run in batches and test classes. Each typically sends a class a fixed message and verifies it returns the predicted answer." In practical terms this means that you write programs that test the public interfaces of all of the classes in your application. This is not requirements testing or acceptance testing. Rather it is testing to ensure the methods you write are doing what you expect them to do. This can be very challenging to do well. First of all, you have to decide what tools you will use to build your tests. In the past we had large testing engines with complicated scripting languages that were great for dedicated QA teams, but weren't very good for unit testing. What journeyman programmers need is a toolkit that lets them develop tests using the same language and IDE that they are using to develop the application. Most modern Unit Testing frameworks are derived from the framework created by Kent Beck for the first XP project, the Chrysler C3 Project. It was written in Smalltalk and still exists today, although it has gone through many revisions. Later, Kent and Erich Gamma (of Patterns fame) ported it to Java and called it jUnit. Since then, it has been ported to many different languages, including C++, VB, Python, Perl and more.
Related articles
Related discussion
-
Creating a Windows Service in VB.NET
by Templario55 (107 replies)
-
High-Performance .NET Application Development & Architecture
by Manjot Bawa (0 replies)
-
An Introduction to VB.NET and Database Programming
by carlosmen (14 replies)
-
Compatibility Issue on Firefox to display on Cursor Location
by dinc3r (1 replies)
-
VB/VB.NET
by surath (7 replies)
Related podcasts
-
The Past, Present and Future of .NET Unit Testing Frameworks
Scott gets a rare chance to sit down in person with developers from three .NET Unit Testing Frameworks. Charlie Poole from NUnit, Jeff Brown from MbUnit, Brad Wilson from xUnit.NET as well as Roy Osherove, the author of the upcoming "Art of Unit Testing."
Events coming up
-
Jul
28
Enterprise Developers Guild - Making Your Code Bullet Proof
Charlotte, United States
Join us Tuesday, July 28, at 6:00 PM in the Mt. Kilimanjaro Room at the Charlotte Microsoft Campus to learn how to make your code bullet proof by our very own Eric Notheisen.
Well explained. More about TDD using C# can be found here Link Text
!--removed tag-->Hello, would it be possible to post all of the code regarding the "Using Mock Objects - DotNetMock" article. The page outlines the process and most of the code, but it'd be great to see the UI that is actually being tested against the mocked version - i.e. it is slightly confusing about where the line is drawn on how much of the actual UI is being tested and being able to execute the real code against the mocked code would clarify how the view and the controller interact.
Many thanks
This thread is for discussions of Test-Driven Development in .NET.