SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

Unit Testing

SharpDevelop integrates with NUnit allowing you to run and debug your unit tests inside the development environment.

First you will need a project to hold your tests. From the File menu, select New and then select Solution... to open up the New Project dialog box.

File new Solution menu item

Expand the C# category and select Class Library from the list of available templates. Choose the project's name and location and then click the Create button.

Now create a simple test class. Select the name of the project in the Project Explorer, right click, select Add and then select New Item.... Select the Unit Test template from the C# category, give it a name and then select the Create button. Adding this template to the project will automatically add the required reference to NUnit.Framework. The code shown below is an example of a very basic test class which you can copy into the file just created.

using NUnit.Framework;  
using System;   
namespace Simple.Tests 
 public class MyTest   
  public void FailingTest()    
   Assert.Fail("This test fails.");    

From the View menu select Tools and then Unit Tests.

View Unit Tests menu item

This opens up the Unit Tests window.

Unit test window

To run the test from the Unit Tests window click the Run tests toolbar button Run tests button, or right click a test, and select Run tests.

Run tests menu item

After a test run, unit tests that pass are shown in green, those that fail in red and those that have not been run in yellow.

Tests results

Unit test results - more complicated

As the tests are run messages are displayed in the Output window and after the tests have completed failing tests are added to the Errors window.

Errors window with test failures

Tests can be run from the source code editor by right clicking the test method or test class and selecting one of the Unit Testing menu options.

Running tests from the text editor

The menu options allow you to run the test and show the result in the Unit Tests window, or run the test with the debugger so you can step through the code, or run the test and check for code coverage. The last two menu items are also available when running tests from the Unit Tests window.

< previous | home | next >

Published Jul 05 2006, 11:57 AM by MattWard
Filed under:


No Comments
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this ( email address.