'Extract Xunit test class name from ITestOutputHelper object (C# )
Can I use the ITestoutputHelper injected object to get the calling class name?
Solution 1:[1]
After a great comment by @Zden?kJelínek, I end up implementing this static extension function to ITestOutputHelper
.
public static string GetTestClassName(this ITestOutputHelper helper)
{
var type = helper.GetType();
var testMember = type.GetField(FieldName, BindingFlags.Instance | BindingFlags.NonPublic);
return((ITest) testMember.GetValue(helper)).TestCase.TestMethod.TestClass.Class.Name;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |