I've current got a line at the top of all my tests that looks like this:
Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);
Seems like it'd be nice if I could just put this in my Init method (the one tagged with [Setup]
). I thought this would work but no matter what number I put in for the stack frame the closest I can get is Init
. Not what I want, but very close:
string methodName = new StackFrame(0).GetMethod().Name;
Console.WriteLine(methodName);
I think this just might not be possible, given the way that Nunit runs tests.
Why do this, you say? Because in my console output it'd be nice to see where a new test started so if they both hit the same code and output different values, I'll know which one did what, without having to debug.
The following could help me:
string testName = NUnit.Framework.TestContext.CurrentContext.Test.Name;
string testFullName = NUnit.Framework.TestContext.CurrentContext.Test.FullName;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With