In the previous post, I wrote about installing MonoDevelop on Ubuntu 10.04 LTS. This post will be about installing NUnit integration for MonoDevelop.
I want to do some testing of my project with unit testing. I’ve search the web and many site (and videos) claim that MonoDevelop has build in unit testing support as well as class templates for NUnit, but I just couldn’t find anything in the IDE pertaining unit testing. After more research, I found that I need to install NUnit Plugin for Mono Develop (monodevelop-nunit). The following are the steps.
Install NUnit Plugin for Mono Develop.
Install the plugin from the software center.
After installing, MonoDevelop will have an option for Unit Testing under the View menu as well as panels for running and showing results for tests.
Create Test Project
To write unit tests, we need to first create a .NET library project for our test. Though NUnit plugin adds a new solution type to MonoDevelop called “NUnit Assembly Test Collection”, I have not yet figured out the intent or how to use this project type; therefore, we’ll house our tests in a regular library project.
After the test project has been created, the project needs to reference the nunit.framework assembly. Double click on references, go into All tab, and check the nunit.framework. I found that there are two copies of the assembly of same version. I believe one came with Mono and one just install the second time. I haven’t found difference between the two copies.
Writing Unit Tests
After having created a test project, we’re ready to write our unit tests. Create a new C# class in our test Project. Our test class will need to use the features in the NUnit.Framework namespace, which is defined in the nunit.framework assembly we referenced in the previous section.
In addition, the class need to be embellished with TestFixtureAttribute ([TestFixture]), and test method with TestAttribute ([Test]). The following is one of my test class.