5

I have nunit test with some test cases.

[TestCase(1,Description="first")]
[TestCase(2, Description="second")]
public void A(int a)
{
    Assert.True(a==1);
}

How can I get description of each test case. I try do it at TestFinished() method of EventListener, but I can get only array of descriptions.

RB.
  • 36,301
  • 12
  • 91
  • 131
user1590561
  • 583
  • 2
  • 6
  • 17
  • What for do you need test description? – Alexander Stepaniuk Feb 23 '13 at 18:05
  • 2
    I'd suggest that you write your test names to represent what you're testing. For example, in an mvc4 project I work on I'd name tests like this. __input_is_null_NullArgumentException_Expected. I've moved to this naming convention recently and been quite strict with, it's worked well for me. – Eogcloud Jun 24 '13 at 20:57

2 Answers2

2

Have you tried NUnit's CurrentContext?

Perhaps (I've not looked) the value of Description is in TestContext.CurrentContext.Test.Properties, you'll need at least NUnit 2.6.2 see NUnit 2.6.2 TestContext.CurrentContext always null

Community
  • 1
  • 1
Tully Ernst
  • 105
  • 1
  • 10
2

I think you should see take a look at this answer here

But when I tried what is mentioned in this answer, it gave me the object of Properties List itself which unneeded, It worked with me fine when I used instead:

TestContext.CurrentContext.Test.Properties.Get("Description")

I hope it works with you too

Amado Saladino
  • 2,114
  • 23
  • 25