tags:

views:

197

answers:

2

Hi,

How do i Assert to test a method that has no return value.

For example: public void UpdateProfileVersion (ILimitedDataConnection connection, int effectiveUserID, int OrgID, int EntityTypeID) { OrgStoredProcedures.OrgGroupProfileUpdateData(connection, Convert.ToInt32(OrgGroupProfileStatus.History), OrgID, EntityTypeID); }

How do i do an assertion of this method in my test method. I find no corresponding methods in Assert class to do an assertion for a method that returns no value.

Regards, Damodar

+1  A: 

I went through the process of working out how to get started with NUnit a couple of days ago, and it isn't obvious how to get started.

First install NUnit.

To make unit tests, first add a new Class Library project to the solution. Add a reference to nunit.framework by right-clicking on References in the Solution Explorer and finding it in the .NET tab. Add a reference to the project you want to test (this will be in the Projects tab). Inside the test class, you will be to be using NUnit.Framework and the project you want to test. Then create unit tests. For example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using NUnit.Framework;
using PrimeGenerator; // my project

namespace NUnitTestProject
{
    [TestFixture]
    public class Tests
    {
        [Test]
        public void NaiveTest()
        {
            int n = 5;
            ArrayList results = Program.generatePrimesNaive(n); // this is a static method that generates the first n primes
            ArrayList expected = new ArrayList();
            expected.Add(2);
            expected.Add(3);
            expected.Add(5);
            expected.Add(7);
            expected.Add(10);
            Assert.AreEqual(expected, results);
        }
    }
}

To run tests, open NUnit and open the compiled class library. In my case, this is \NUnitTestProject\bin\Debug\NUnitTestProject.dll. Tests can now be run. Alternatively, tests can be run from inside Visual Studio with TestDriven.Net. Simply right-click and select Run Test(s).

David Johnstone
+2  A: 

Take a look at the GetStarted section of the NUnit site. It should contain enough information for you to write your first test.

The question does not contain enough information to answer the plugin part.

BengtBe