bgeek.net

CodeCamp: in need input

Posted by Owen Evans on Monday, August 18th, 2008

Ok so this is a bit of a plea.
I’ve a week or so to work on my CodeCamp presentation “MVC and Me” (ok so would have been cooler to link to flight of the navigator but that’s too hard for me to pull off) and I’m still trying to gather as many ideas about what [...]

continue reading

Split And Sprint

Posted by Owen Evans on Thursday, August 14th, 2008

In a forthcoming book (before you ask I’ve no idea what the title is) there’s a little case study about the first project i ever truly worked on as a developer. The project and the team have some of my fondest memories, and I’d want to work with any of the people in the small [...]

continue reading

Post 300

Posted by Owen Evans on Friday, August 8th, 2008

Ok I just had to cheat an make up a reason to post. But this is my 300th post, this blog has been going for more than 5 years (25 Feb 2003 was my first post, those heady days of university). that’s 1992 days, so an average of one post every 6.64 days. (my goodness [...]

continue reading

NSpecify Nunit add-in fix for InitializeFunctionality methods

Posted by Owen Evans on Friday, January 18th, 2008

Well I still exist!

Recently I’ve been moving more and more into understanding how a specification test should be written using NSpecify a really nice framework for running tests.

Also I’ve been seriously involved in getting the teams build process up and running in a much more meaningful form, as such I’ve noticed a bug in the nunit add-in for NSpecify.

It wasn’t running any of my InitializeFunctionality (Incidently i think this would be better named as ContextSetup and Functionality renamed to Context) methods.

I looked in the code and realised none of the setup’s or teardowns were getting wired up, a quick modification and there all hunky dory.

2 changes are required:

NSpecifySuiteExtension.cs should look like this

using System;
using System.Reflection;

namespace NUnit.Core.Extensions
{
    /// <summary>
    /// NSpecifySuiteExtension extends test suite and creates a fixture that runs every specification implementing the NSpecify attributes.
    /// Because it inherits from TestSuite, rather than TestFixture, it has to construct its own fixture object and find its
    /// own specifications. Everything is done in the constructor for simplicity.
    /// </summary>
    internal class NSpecifySuiteExtension : TestSuite
    {
        #region C'tors

        /// <summary>
        /// Initializes a new instance of the <see cref="NSpecifySuiteExtension"/> class.
        /// </summary>
        /// <param name="fixtureType">Type of the fixture.</param>
        public NSpecifySuiteExtension(Type fixtureType)
            : base(fixtureType)
        {
            // Create the fixture object. We could wait to do this when
            // it is needed, but we do it here for simplicity.
            Fixture = Reflect.Construct(fixtureType);
            fixtureSetUp = Reflect.GetMethodWithAttribute(fixtureType, Constants.InitializeFunctionalityAttribute, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, true);
            fixtureTearDown = Reflect.GetMethodWithAttribute(fixtureType, Constants.CleanupFunctionalityAttribute, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, true);
            // Locate our test methods and add them to the suite using
            // the Add method of TestSuite. Note that we don't do a simple
            // Tests.Add, because that wouldn't set the parent of the tests.
            foreach (MethodInfo method in fixtureType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                Attribute spec = Reflect.GetAttribute(method, Constants.SpecificationAttribute, true);
                if (spec != null)
                {
                    Add(new NSpeicifyTestMethod(method));
                }
            }
        }

        #endregion
    }

    internal class NSpeicifyTestMethod : NUnitTestMethod
    {
        public NSpeicifyTestMethod(MethodInfo method)
            : base(method)
        {
            setUpMethod = Reflect.GetMethodWithAttribute(FixtureType, Constants.SetupResourcesAttribute, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, true);
            tearDownMethod = Reflect.GetMethodWithAttribute(FixtureType, Constants.DestroyResourcesAttribute, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, true);
        }
    }

}

And constants.cs just gets updated to this:

namespace NUnit.Core.Extensions
{
    /// <summary>
    /// The constants
    /// </summary>
    public class Constants
    {
        public const string FunctionalityAttribute = "NSpecify.Framework.FunctionalityAttribute";
        public const string InitializeFunctionalityAttribute = "NSpecify.Framework.InitializeFunctionalityAttribute";
        public const string CleanupFunctionalityAttribute = "NSpecify.Framework.CleanupFunctionalityAttribute";
        public const string SpecificationAttribute = "NSpecify.Framework.SpecificationAttribute";
        public const string SetupResourcesAttribute = "NSpecify.Framework.SetupResourcesAttribute";
        public const string DestroyResourcesAttribute = "NSpecify.Framework.DestroyResourcesAttribute";

        public const string SuiteBuilders = "SuiteBuilders";
    }
}

I’ve got a patch file if I can get the people who have write access to the NSpecify repository to apply it (there are no mailing lists for me to send it to)

Here it is

kick it on DotNetKicks.com

Sphere: Related Content

Posted in: [|||].

discussion by DISQUS

Add New Comment

Viewing 1 Comment

blog comments powered by Disqus