Browse DevX
Sign up for e-mail newsletters from DevX


Unit Testing in .NET : Page 6

You have been given the task of creating some business objects for a new .NET project. The UI has not been created (or designed) yet, so you start coding right away. After creating the first few objects, you decide that maybe you should do some unit testing. This article shows you how.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

It is possible to use the NUnit GUI as the debugging application in your .NET project. Even though your project does not have a UI, you can run your business object project. This allows you to set a breakpoint in either your TestFixture code or your business object code. When the testing process hits the breakpoint, you'll be able to step through your code using the .NET debugger. To set this up, follow these steps:
  1. Right-click on the project in your solution and select Properties.
  2. In the Property Pages window, expand the Configuration Properties folder.
  3. Select the Debugging option.
  4. In the Start Action group of properties, change the Debug Mode property to Program.
  5. Click the Apply button.
  6. Now click on the ellipsis to the right of the Start Application properties and navigate to and select nunit-gui.exe.
  7. Click OK.
After going through this process, you can set a breakpoint and press F5 to start a debugging session. After compiling your project, the NUnit GUI application starts. Click on the Run button. When the test process gets to your breakpoint, you will be able to use the debugger.

The NUnit framework is an excellent tool for testing business objects. It is very easy to construct test cases to test calling methods on a business object with several different parameter values to make sure that the methods return expected results each time. It is also capable of detecting expected exceptions; if you call a method in a way that you expect to throw a specific exception, you can test for this also.

Dan Jurden is a Senior Application Developer for EPS-Software Corp. He is a Microsoft Certified Professional and co-authored the book "Creating Visual FoxPro Applications Using Visual FoxExpress" with Bob Archer, published by Hentzenwerke Publishing. Dan was also the Technical Editor for "CrysDev: A Developer's Guide to Integrating Crystal Reports," also published by Hentzenwerke Publishing. He has authored articles published in CoDe Magazine, Fox Talk, MSDN Brazil, SDGN Magazine, and Universal Thread Magazine, dealing with SQL Server, .NET, MySQL, VFP, and other topics. Dan has presented topics at the German DevCon, Essential Fox, SQL Server Live!, SDC Netherlands, and GLGDW conferences. He has been developing client/server applications using SQL Server Crystal Reports for over eight years.
Thanks for your registration, follow us on our social networks to keep up-to-date