V3 Documentation
Search

NCrunch.Framework.Category Attribute

NCrunch.Framework Attribute

Purpose

This attribute allows you to specify categories for tests within your solution.

Although test frameworks generally have their own attributes and syntax for declaring categories, this attribute is an alternative option that will be recognised by NCrunch only.

This attribute can be used to specify categories at both test level and fixture level.

This attribute can also be applied at assembly level, in which case all tests within the assembly will be considered categorised.

Declaration In NCrunch.Framework.dll

namespace NCrunch.Framework
{
	[AttributeUsage(AttributeTargets.Method
		| AttributeTargets.Class
		| AttributeTargets.Field,
		| AttributeTargets.Assembly
		AllowMultiple = true)]
	public class CategoryAttribute: Attribute
	{
		public CategoryAttribute(string category)
		{
			Category = category;
		}

		public string Category { get; private set; }
	}
}

You can declare this in your own code if you want NCrunch to use it - or otherwise reference the attribute from NCrunch.Framework.dll.

Usage Example

[NCrunch.Framework.Category("Integration")]
[Test]
public void MyTest()
{
	...

Recommendations

Test categories are very useful when configuring NCrunch engine modes.