Posts Tagged ‘NUnit’

NUnit Framework for .NET Compact Framework and Silverlight

February 26, 2010

Unofficial NUnit Framework port for .NET Compact Edition and Silverlight.

Only nunit.framework project.

Now Add NUnit-2.5.3.9345 for .NET CF 3.5 and Silverlight 3.0. Please checkout and build via Visual Studio 2008 yourself.

Visit the project site here.

NUnit_Framework_for_CF_2.5.3.9345.zip

NUnit_Framework_for_Silverlight_2.5.3.9345.zip

Advertisements

NUnitExtension.DataDriven – an NUnit AddIn for data-driven testing

July 14, 2008

DataDriven Extension is an NUnit Addin that allows you to create test cases from any data sources (like database or plain text files etc.) and can used for parameterized test.

DataFactoryAttibute (like the FactoryAttribute in NUnit 2.5 alpha 3), indicate class of the test case factory. You can also set some arguments for creating test cases.

Test case factory class must have a defualt constructor and a method with IEnumerable as the return value for create test cases. And this method should be marked by the DataSourceAttribute (like the TestCaseFactory in NUnit 2.5 alpha 3).

TestCaseItem (like the TestCaseData in NUnit 2.5 alpha 3) is a constraint-oriented test case task class. You can set the arguments for parameterized test method or normal test method and set some constraints to check the return value or expected exception throwed by the test method.

You can download here:

NUnitExtension.DataDriven_0.1_alpha.zip

To get the source code or more information, please visit the project site:

http://code.google.com/p/nunit-extension-datadriven/

Request

  • NUnit 2.5 alpha 3 (May be compiled against other NUnit versions)
  • .NET Framework 2.0 (Not tested under .NET Framework 1.1 and mono)

Install

  1. Copy the NUnitExtension.DataDriven.AddIn.dll to “…\NUnit 2.5\net-2.0\addins\”.
  2. Add reference to NUnitExtension.DataDriven.dll and write your own data-driven tests.

Example

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using NUnit.Framework.Syntax.CSharp;
using NUnitExtension.DataDriven;

[TestFixture]
public class DataDrivenTest
{
    Random random = new Random();

    [DataFactory(typeof(RandomFactory), 10)]
    public double Add(double a, double b)
    {
        return a + b;
    }

    [DataFactory(typeof(RangeFactory))]
    public double NextDouble()
    {
        return random.NextDouble();
    }

    [DataFactory(typeof(ExceptionFactory), typeof(int))]
    public void ThrowException(Type exceptionType)
    {
        if (typeof(Exception).IsAssignableFrom(exceptionType))
            if (exceptionType.GetConstructor(new Type[0]) != null)
            {
                throw (Exception) Activator.CreateInstance(exceptionType);
            }
    }
}

public class RandomFactory
{
    [DataSource]
    public IEnumerable GetTestCases(int count)
    {
        Random random = new Random();
        for(int i = 0; i