Поэтому я реализовал следующий атрибут:
Код: Выделить всё
public class CustomTestMethodAttribute : TestMethodAttribute
{
private string _meta1;
private string[] _meta2;
public CustomTestMethodAttribute(string meta1, string[] meta2, string? displayName = null) : base(displayName)
{
_meta1 = meta1;
_meta2 = meta2;
}
public override TestResult[] Execute(ITestMethod testMethod)
{
MethodInfo methodInfo = testMethod.MethodInfo;
Dictionary metaProperties = new()
{
{
"task", new Dictionary
{
{ "className", testMethod.TestClassName },
{ "method", methodInfo.Name },
{ "meta1", _meta1 },
{ "meta2", _meta2 }
}
}
};
// that is the line that doesn't work
testContext.WriteLine($"META_INFORMATION={JsonSerializer.Serialize(metaProperties)}");
return new TestResult[] { testMethod.Invoke(null) };
}
}
Код: Выделить всё
[CustomTestMethod(meta1: "12345", meta2:new []{"12345", "23456"})]
public void MyTestMethod()
{
...
}
Код: Выделить всё
[TestClass]
class Test1
{
public TestContext TestContext { get; set; }
...
}
Если доступ к TestContext внутри атрибута невозможен - как я могу использовать что-то вроде testContext.WriteLine() в своем атрибуте?
Подробнее здесь: https://stackoverflow.com/questions/789 ... dattribute