How to propagate a PropertyAttribute on a class to its methods in the XML output? #4713
Unanswered
marco-eckstein
asked this question in
How to
Replies: 1 comment
-
Instead of using XSLT you can make your own variant of the property attribute that will also apply the property to the tests - e.g. like this public class MyAttribute: PropertyAttribute, IApplyToTest
{
private readonly string propertyName;
private readonly string propertyValue;
public MyAttribute(string propertyName, string propertyValue) : base(propertyName, propertyValue)
{
this.propertyName = propertyName;
this.propertyValue = propertyValue;
}
public override void ApplyToTest(Test test)
{
base.ApplyToTest(test);
if (test.HasChildren)
{
foreach (var child in test.Tests)
{
if (child is TestMethod testMethod)
{
testMethod.Properties.Add(propertyName, propertyValue);
}
}
}
}
} and then you can use it like this (note that I had to explicitly add [My("MyProperty", "MyValue")]
[TestFixture]
public class Tests
{
[Test]
public void Test1()
{
Assert.Pass();
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have annotated a test class with an NUnit.Framework.PropertyAttribute. This results in the XML test results file having this attribute as property child element of the element that represents this test class.
Now I also want this attribute as property child element of the elements that represent the test methods, but I do not want to annotate the test methods with this attribute explicitly. What are the best ways to do this?
It may be possible by writing an XSLT stylesheet and passing its location to the command line runner. But since I have no experience with XSLT, I may prefer another approach.
Also posted at Stack Overflow.
I am using NUnit 3.
Beta Was this translation helpful? Give feedback.
All reactions