Software Development

Visual Studio 2008 offers developers more testing options

Visual Studio 2008 Professional Edition includes Microsoft's own unit testing offering. Tony Patton offers more details about the recent changes in Visual Studio 2008 and surveys the current landscape of .NET testing options.

Unit testing has evolved from a fringe activity to an industry-accepted way to develop software. This change in attitude was aided by the introduction of numerous freely available testing frameworks -- most notably, NUnit.

Microsoft's testing options have drawn the ire of the development community for years because there has been a lack of testing support from the company. Non-Microsoft tools require extra product installations and setup, so many developers called for Microsoft to offer such tools with its IDE. Finally, Visual Studio 2008 Professional Edition includes Microsoft's own unit testing offering.

I'll offer more details about the recent changes in Visual Studio 2008 and survey the current landscape of .NET testing options.

Testing options in Visual Studio 2008 Professional Edition

Visual Studio 2005 Team System included Microsoft's testing engine (MSTest), but many developers still clamored for the testing tools to be available to a wider audience. Their efforts paid off, and MSTest is now available in Visual Studio 2008 Professional Edition.

The new Test drop-down menu within the IDE provides easy access to the testing framework. It allows you to author, generate, and run tests. Other changes have been introduced as well. For instance, a new Run Tests context-menu option has been added to the MSTest engine to simplify the execution of tests.

Test-driven development options

A basic tenet of eXtreme programming is test-driven development. The goal is to create tests before developing any code. This goes against traditional programming; instead of writing functional code and then testing code as an afterthought (if testing is performed at all), you start with the test code.

You make sure the test is correct according to the necessary logic. With the test complete, it is available when the code is ready, and you quickly know if the code performs as desired. Basically, you develop code that will pass the test.

A key part of test-driven development is the automated unit test that properly tests code functionality. Testing frameworks provide a vehicle for creating and running these tests. Various frameworks exist for .NET developers, including the following:

  • NUnit: An open source unit-testing framework for the .NET platform. It is the leader in this category, as it mimics the JUnit Java offering for the .NET platform; that is, it brings test-driven development to .NET. NUnit provides both a GUI and command-line interface. It also promotes unit testing your .NET code after coding is complete or using the test-driven approach to development. (Learn more about this framework by reading my article, "NUnit allows effective unit testing with .NET applications.")
  • xUnit.net: A freely available testing framework available via Microsoft's version of open source with the CodePlex site. It was designed with a goal of closely aligning itself with the .NET Framework. (One of the developers of xUnit.net originally worked on NUnit.) xUnit.net was built using .NET Framework 2.0; it does not require any installation, and it offers better integration with source control tools. xUnit.net focuses heavily on test-driven development as opposed to just testing, so there are some differences with NUnit. xUnit.net is the latest to join the pool of testing frameworks.
  • MbUnit: MbUnit or the Generative Unit Test Framework for the .NET Framework is offered free of charge. It was built using the .NET Framework, and it promotes test-driven development. It offers both command-line and GUI interfaces along the lines of the same features available in NUnit.
  • QuickUnit.net: A simple testing framework written in C# for .NET applications. It is a minimalist approach to testing for developers who ignore writing unit tests and test-driven development. It can be used as a first step to become familiar with testing.
  • csUnit: A freely available testing framework that promotes test-driven development. It offers a graphical interface and easy integration with Visual Studio 2005.

Visual Studio add-ons

There are a few Visual Studio add-ons that make it easier to use the various testing frameworks within the IDE. One of the more popular products is TestDriven.NET; however, unlike the testing frameworks, it is not free. TestDriven.NET allows you to use the features of the testing framework from within Visual Studio via one click of the mouse. It works with all versions of Visual Studio.

Will developers migrate from their current testing tools?

The Professional Edition of the IDE is so popular that, theoretically, the inclusion of MSTest makes unit testing available to the masses. The requirements for third-party products to support testing are gone. Developers can be up and running with unit testing out of the box.

While it is a great addition, it makes me wonder if it will encourage developers to migrate from existing testing tools and adopt a test-driven approach for their projects. There are a number of solid tools currently available, and I think it will be hard to pull developers from these tools.

Do you plan to check out the new unit testing options in Visual Studio 2008 Professional Edition or stick with your current tools? Share your thoughts with the Visual Studio Developer community.

Tony Patton began his professional career as an application developer earning Java, VB, Lotus, and XML certifications to bolster his knowledge.

---------------------------------------------------------------------------------------

Get weekly development tips in your inbox TechRepublic's free Visual Studio Developer newsletter, delivered each Wednesday, contains useful tips and coding examples on topics such as Web services, ASP.NET, ADO.NET, and Visual Studio .NET. Automatically subscribe today!

About

Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a productio...

10 comments
pnunbe
pnunbe

Hi, is it possible to obtain code coverage data and to perform Sql Server unit tests under VS 2008 Professional? I did not succeed; did I miss something or do I need another edition of VS or some commercial testing framework?

alam.alam010
alam.alam010

can you help me know what problem is there when I run a console program in visual studio after the output the console disappears instantly and the whole process takes around 2 seconds or less.

rob_donia
rob_donia

NMate Addin is an option for Visual Studio 2005. NMate will Integrate NUnit or MbUnit into Visual Studio. It can also Code Generate Tests right from the IDE. Its New but is promising. http://ngenerator.dyndns.biz/dnn_site/

BALTHOR
BALTHOR

You could even try migration from C# to C##.But I doubt if even Steve could recommend a proper algorithm without going deep into the basic source code concept itself.And that's where most get stuck.It gets like a religion down there---

v-frerec
v-frerec

I'm really excited about the new testing options in VS 2008, it can only mean better support and quicker solutions to issues. ---------------------- Fred Reckling Microsoft Grassroots Manager www.microsoft.com/2008jointlaunch

serv7
serv7

Definitely a good move for makers of development environments because after all it 'is' development. If Microsoft makes some migration tool I think the transation from current testing tools will be inevitable. I believe the area that needs work, however, is not in method level unit testing, but in solid functional testing tools that regression test the UI.

Tony Hopkinson
Tony Hopkinson

Put a press any key to close on the end of the console output. Maybe with a macro definition or a command line switch to put it in. Or of course you could simply redirect the output to a file. Just put > test.txt in the debug tab command line parameters of the project options.

Justin James
Justin James

There's never a downside with rolling something like this directly into the toolset, from where I sit. :) J.Ja

rvasconi
rvasconi

We recently take over support for an app in MS C++ 6.0. We are conducting a project to migrate developpment to VS 2008. I'm very interested in using automated test tool for enhancement development as well as for regression test. Do you think this new tools could be a help to us?

Tony Hopkinson
Tony Hopkinson

Code rot generally harms unit, integration and regression testing, so if it's legacy app, you are going to have to change it to test it in any sensible fashion. Now if you get a difference in regression testing, where is the mistake. It could be anything from .net works differently to accidentally fixing a bug in the existing software... No tools, new or otherwise will help you until you've decided what to test for, and how.

Editor's Picks