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
-
Compatibility Issue on Firefox to display on Cursor Location
by ansari.wajid (0 replies)
-
An Introduction to VB.NET and Database Programming
by yen (12 replies)
-
Creating a Windows Service in VB.NET
by codet (102 replies)
-
VB/VB.NET
by surath (7 replies)
-
VB.NET or C#?
by siddeshwar (3 replies)
Related podcasts
-
Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner
One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
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.