NUnit factories

I was getting mad to find out how to use factories on NUnit. I’ve been using factory methods with MBunit and they’re definetly helpful when you need to execute a test using several imputs. What was confusing me is the NUnit documentation: I’ve googled something like “NUnit factory” and the first results were pointing me to the following link , that is the official documentation. Unfortunely the Factory attribute have been dropped from the latest versions of NUnit (I’m using the 2.5.7) and a part from the release notes there are no infos on the changes that have been made. By the way, NUnit (and MBUnit as well) is a lot better than the MSTests for a lot of aspects, factories are one of them.

A sample test:

[Test, TestCaseSource(typeof(TestHelperFactory), "TestCases")]
public void WriteImageToFolder_UsingDifferentResolutions_Test(string fileName, Int64 quality, string message)
   string fullFilePath = string.Format("{0}\\{1}", _path, fileName);
   ImageGenerator imageGenerator = new ImageGenerator();
   Bitmap resultImage = imageGenerator.CreateTextImage(message, 20);
   resultImage.SaveJPGCustomQuality(fullFilePath, quality);


public class TestHelperFactory
    public static IEnumerable TestCases
            string message1 = "This is a sample test message";
            yield return new TestCaseData("Message1_quality100.jpeg", 100L, message1);
            yield return new TestCaseData("Message1_quality90.jpeg", 90L, message1);
            yield return new TestCaseData("Message1_quality80.jpeg", 80L, message1);
            yield return new TestCaseData("Message1_quality70.jpeg", 70L, message1);
            yield return new TestCaseData("Message1_quality60.jpeg", 60L, message1);
            yield return new TestCaseData("Message1_quality50.jpeg", 50L, message1);
            yield return new TestCaseData("Message1_quality40.jpeg", 40L, message1);
            yield return new TestCaseData("Message1_quality30.jpeg", 30L, message1);
            yield return new TestCaseData("Message1_quality20.jpeg", 20L, message1);
            yield return new TestCaseData("Message1_quality10.jpeg", 10L, message1);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s