in my UI tests I created Custom Attribute [TestCaseId] to be used in tests:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class TestCaseIdAttribute : PropertyAttribute
{
public TestCaseIdAttribute(int testCaseId)
: base(testCaseId.ToString()) { }
}
which I use like here:
(I use it in [TearDown] to mark Azure Tests as Automated but it's not relevant here)
[TestCaseId(123456)]
[Test]
public void TestScenario_1()
{
Assert.That(true);
}
and this works as intended, I access TestCaseId via: _testContext.Test.Properties["TestCaseId"].First();
to retrieve the value.
When I use [TestCase] attribute instead of [Test], like here:
[TestCaseId(123456)]
[TestCase(1, 2)]
public void TestScenario_1(int arg0, int arg1)
{
Assert.That(arg0 != arg1);
}
I access via:
_testContext.Test.Method.MethodInfo.CustomAttributes.FirstOrDefault(a => a.AttributeType.Name == "TestCaseIdAttribute").ConstructorArguments[0].Value;
However, I don't know how to read TestCaseId having different custom attribute [TestCaseId] for each [TestCase], like here:
[TestCaseId(123456)]
[TestCase(1, 2)]
[TestCaseId(666666)]
[TestCase(9, 8)]
public void TestScenario_1(int arg0, int arg1)
{
Assert.That(arg0 != arg1);
}
Any idea how to match [TestCaseId] attribute to each [TestCase]?
I tried to match an object from _testContext.Test.Method.MethodInfo.CustomAttributes
to my TestName but there is no any Test Name included there.
It would be best to have a property assigned to [TestCase] the same way as it is to [Test]. I use NUnit 4.