Home > Microsoft .Net Development Tips > Application Testing and Security > Automate .NET testing
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

APPLICATION TESTING AND SECURITY

Automate .NET testing


Ed Tittel
05.06.2003
Rating: -3.25- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Testing is an essential discipline in developing code, not only to catch and correct outright mistakes, but also to check how that code behaves thoroughly and systematically. Ideally, each individual block of code should be tested by itself to make sure it works as expected, handles boundary conditions properly, and given particular sets of input produces expected and correct output. That's where NUnit comes into play.

NUnit is a unit-testing framework for all .NET languages available through the sourceFORGE.net project. Originally devised as a unit testing environment for Java called JUnit, NUnit represents a port to the .NET environment. It's a text console based environment that works with Windows 32 environments that based on the copyleft licensing scheme developed for the GNU project (in fact, NUnit is part of the GNU Tools for Win32 that falls within the general program). NUnit supports C#, C++ and Visual Basic and is designed to work within the general .NET and Visual Studio environment.

By visiting the NUnit homepage you can download either built classes or source code for NUnit. Those working with stable, released versions of Windows (such as Windows 2000 or XP) can probably use the built classes; those working with RC2 of Windows Server 2003 will want to grab source, because some tweaking will be necessary to make it run (details appear in Bill Wagner's story "Test .NET Code Automatically with NUnit").

Once you've built or installed NUnit, you can run it with the sample tests it includes by running the NUnitGUI project to load its tests and selecting the Browse button to load one of the assemblies provided. You can try out the samples by selecting the SampleMoney.dll assembly to load it, then using the TypeName box to determine which types of assemblies have defined tests. By clicking the Run button, you can execute all defined tests and observe the results in the bottom of the NUnit console window.

Basically, NUnit uses reflection to find test methods within any unit test code you create and identify as such. To create a test suite, create a new class to execute your tests. This new class must derive from the TestCase class, which is part of the basic NUnit environment. Also, any test method in that new class should contain a void return type and take no parameters.

Within NUnit, the Assert method tests the output of a test, where strings may be used to specify failures for individual test elements. Because some test suites require setup or shutdown code before they execute, the NUnit TestCase class provides virtual functions for such activities. Thus, for example, the SetUp method may be used to initialize counters, establish values, and so forth.

To make NUnit integrate properly with TestCase derived classes, they must also include a static method that returns an ITest interface. NUnit provides a constructor that handles this in a single statement. For the complete source code to a sample test class, see Wagner's NUnit Tests page. Working with NUnit is easy, relatively straightforward, and should help make unit testing simpler, faster and easier.


Ed Tittel is a principal at LANWrights, Inc. a wholly-owned subsidiary of iLearning.com, where he writes and teaches on a variety of subjects, including markup languages, development tools, and IT certifications. Contact Ed via e-mail at etittel@lanw.com.


Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
.NET Framework security best practices
New features in Windows 7 bring new UI considerations for developers
Podcast: Windows CardSpace authors speak
Book excerpt: Java EE and .NET security interoperability
Book excerpt: Advanced Windows Debugging
Book excerpt: Pragmatic unit testing in C# with NUnit
Security interoperability with .NET/WSE and WebLogic Workshop 8.1
Windows Developments: Product news, December 2007
How to avoid regression bugs while adding new features
VB code: New additions, November 2007
VB code: Application security downloads

Application Testing and Security
Test-driven development in .NET yields complete unit test coverage
How to write installers in Vista that work correctly under UAC
How to elevate programs' privileges correctly using Vista's UAC
Internet Explorer 8 beta's development tools add source visualizations
Microsoft previews new features in Visual Studio 2010
Advanced Windows Debugging Book Chapter and Podcast
Book excerpt: Advanced Windows Debugging
Book excerpt: Pragmatic unit testing in C# with NUnit
Security interoperability with .NET/WSE and WebLogic Workshop 8.1
How to avoid regression bugs while adding new features

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
common test platform  (SearchWinDevelopment.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts