Create Custom Test Category Attributes in Visual Studio

In the past, for each class library project we create in Visual Studio, we have maintained separate unit test and integration test projects.  This has allowed us to easily configure continuous integration with TFS to run a given project’s unit tests on check-in and run the full suite of unit and integration tests on a nightly build.
With the introduction of Visual Studio 2010, build types now can filter tests based on test categories. 

For example, I can categorize a given test as a unit test by doing the following:

        [TestClass]
    public class Test
    {
        [TestMethod]
        [TestCategory("UnitTest")]
        public void IsValid_returns_false_when_quantity_large()
        {
        }
    }



This allows us to consolidate all tests into one project and distinguish by categories.  The only issue is that these categories are based on strings that the developer must type, and this can create inconsistencies using magic strings which may not be noticed during the course of development.

In order to get around this, another option is to create your own custom test category attributes that return the proper string.  Microsoft has provided a base class, TestCategoryBaseAttribute for this very purpose.

         public class UnitTestAttribute : TestCategoryBaseAttribute
    {
        public UnitTestAttribute()
        {}

        public override IList<string> TestCategories
        {
            get { return new List<string> {"UnitTest"}; }
        }
    }


By overriding the TestCategories property, you can return the appropriate string(s) that represent this classification.  In this case, we are returning the same string that the previous test category provided.

In order to use this attribute, you merely need to add it to a given test method like so.

        [TestClass]
    public class Test
    {
        [TestMethod]
        [UnitTest]
        public void IsValid_returns_false_when_quantity_large()
        {
        }
    }


With this kind of flexibility, if you had a limited list of attributes that you wanted to provide to developers, you could also create an enum type and pass that into the constructor of the custom test category attribute. 

Just create an enum type.

         public enum Category : int
    {
        UnitTest = 0,
        IntegrationTest = 1
    }


Then, create the attribute using the enum as a constructor parameter.

         public class TestCategoryAttribute : TestCategoryBaseAttribute
    {
        private TestCategory _category;

        
        public TestCategoryAttribute(TestCategory category)
        {
            _category = category;
        }

        
        public override IList<string> TestCategories
        {
            get
            {
                var value = Enum.GetName(typeof (TestCategory), _category);
                return new List<string>{ value };
            }
        }
    }



To use the new attribute, you would do the following.

        [TestClass]
    public class Test
    {
        [TestMethod]
        [TestCategory(Category.UnitTest)]
        public void IsValid_returns_false_when_quantity_large()
        {
        }
    }


Hope this helps!

Six Interview Questions for Agile Teams

I was reading through my blogs tonight and came across one that did a nice job of explaining the qualities that an agile team member should possess.  In addition, the writer included a good behavioral interview question for each.
I briefly share each below, but I highly recommend reading the original article.
1. People Who Collaborate
"Think back to a recent project. Give me an example of a time you had to work with other people to make sure that you could finish something. What happened?"
2. People Who Ask for Help
"Think back to your most recent project. Tell me about a time you did not understand something. What did you do?"
3. People Who are Willing to Take Small Steps and Get Feedback
"When you work on your projects outside of work, how do you work?"
4. People Who are Willing To Do Something That is Good Enough for Now
"Tell me about a recent time you did not know everything at the beginning of the project. What did you do?"
5. Adaptable People
"Tell me about a time when you did not have the conditions you would've liked for your project. What did you do?"
6. People Willing to Work Outside Their Expertise
"Tell me about a time you took on work to help the team. What was that like?"
So, tell me dear Reader – what questions do you ask when interviewing candidates for an agile-oriented team?

Motivations

I found this video about what motivates people to be very refreshing.  Basically, if the tasks that people are working on require more than a basic physical action, money rewards don't motivate, but rather demotivate people.  What really motivates others to perform well at conceptual tasks are three things:  autonomy, self mastery, and purpose.  What I find is that Agile practices tend to foster or work within these motivations.  

For example, user stories really help to zero in on the purpose for a given feature request.  "As a [actor], I can [do something], so that I can [accomplish a goal]."  Developers really get a sense for why they are building a piece of functionality rather than just focusing on building a method, etc.  And the prioritization of these stories helps to clarify what is truly important within a sprint.

As well, agile practices promote mastery by emphasizing continual improvement.  Teams are encouraged to use the processes that work for an individual team rather than trying to create a process that will work for an entire organization.  Other principles such as refactoring and unit testing also suggest an intense focus on continually improving the code base.

And finally, the scrum meeting and agile planning in general focus on the team working together on deciding the priorities rather than having a central authority such as a PM do that.  Individuals make themselves accountable to the team by explaining what they accomplished yesterday and what they plan to accomplish for the current day.  This creates a sense of autonomy in those performing the work.

I would be interested to hear your thoughts on the video as well as whether or not you agree that agile practices help to foster these motivations.