Cannot see custom Attributes in Test Explorer
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
NUnit Test Adapter |
Invalid
|
Undecided
|
Unassigned |
Bug Description
I've tried to create a custom attribute based on the NUnit Category Attribute:
// <summary>
/// Attribute used to apply a requirement to a test
/// </summary>
public class RequirementAttr
{
/// <summary>
/// The name of the requirement
/// </summary>
/// <summary>
/// Construct attribute for a given category based on
/// a name. The name may not contain the characters ',',
/// '+', '-' or '!'. However, this is not checked in the
/// constructor since it would cause an error to arise at
/// as the test was loaded without giving a clear indication
/// of where the problem is located. The error is handled
/// in NUnitFramework.cs by marking the test as not
/// runnable.
/// </summary>
/// <param name="name">The name of the requirement</param>
public RequirementAttr
{
}
/// <summary>
/// Protected constructor uses the Type name as the name
/// of the category.
/// </summary>
{
if (requirementNam
}
/// <summary>
/// The name of the requirement
/// </summary>
public string Name
{
get { return requirementName; }
}
}
This compiles, but it doesn't display in VS 2013's test Explorer.
I've then tried:
[AttributeUsag
public class RequirementsAtt
{
public RequirementsAtt
: base(requirements)
{
}
}
Which does display in the Test Explorer, but it only shows:
Requirement[
Your first code sample isn't really an NUnit attribute at all... it's
a copy of one. NUnit will not recognize it at all.
The second sample uses PropertyAttribute as the base. That's an NUnit
attribute, which is designed to be inherited from, so NUnit recognizes
it. Of course, it's not a CategoryAttribute, so it would not work for
selecting tests outside of Visual Studio. It does show up in
TestExplorer, because the NUnit adapter translates all NUnit
Properties to Traits for VS. NUnit uses ToString() to provide VS with
a value for the Trait, which is where String[] (5) comes from.
I see two alternatives for you...
1. Inherit from CategoryAttribute, since what you want is actually a
category anyway. Allow multiple attributes, just as category attribute
does, rather than trying to handle many requirements in a single
attribute.
2. If you prefer to stick with a PropertyAttribute, create multiple
values for the property in the constructor, adding each one separately
to the Properties of the attribute rather than allowing the base class
to do it.
I'm rejecting this as an nunit-adapter bug because (1) the behavior
you are seeing is part of NUnit, not the adapter and (2) it's by
design.
Charlie
On Thu, May 8, 2014 at 10:49 AM, Ryan Ternier <email address hidden> wrote: (AttributeTarge ts.Class | AttributeTarget s.Method | AttributeTarget s.Assembly, AllowMultiple = true, Inherited = true)] ibute : Attribute ibute(string name) tName = name.Trim(); ibute() tName = this.GetType( ).Name; e.EndsWith( "Attribute" )) .Substring( 0, requirementName .Length - 9);
> Public bug reported:
>
> I've tried to create a custom attribute based on the NUnit Category
> Attribute:
>
> // <summary>
> /// Attribute used to apply a requirement to a test
> /// </summary>
> [AttributeUsage
> public class RequirementAttr
> {
> /// <summary>
> /// The name of the requirement
> /// </summary>
> protected string requirementName;
>
> /// <summary>
> /// Construct attribute for a given category based on
> /// a name. The name may not contain the characters ',',
> /// '+', '-' or '!'. However, this is not checked in the
> /// constructor since it would cause an error to arise at
> /// as the test was loaded without giving a clear indication
> /// of where the problem is located. The error is handled
> /// in NUnitFramework.cs by marking the test as not
> /// runnable.
> /// </summary>
> /// <param name="name">The name of the requirement</param>
> public RequirementAttr
> {
> this.requiremen
> }
>
> /// <summary>
> /// Protected constructor uses the Type name as the name
> /// of the category.
> /// </summary>
> protected RequirementAttr
> {
> this.requiremen
> if (requirementNam
> requirementName = requirementName
> }
>
> /// <summary>
> /// The name of the requir...