I developed a CustomAttribute class for my Test Project called like this:
[Test, CustomAttribute]
It's job is to get the current Test name upon entry, using this code:
var testName = TestContext.CurrentContex.Test.Name
Every time it's called there is at least one instance of this string:
AdHockTestMethod
I never knew why; but I put in a filter to ignore it as that is not the Test Name I need. (It appears to be an NUnit internals thing).
My Test Code is simply something like this:
[TestFixture]
public class TestClassName: BaseClass {
[Test, CustomAttribue]
public async Task TestName(){
}
// do something asynchronous here
}
The root cause turned out to be the async method declaration shown above. As soon as I removed that part and used Task.Run with Async (inside the method) everything worked. The updated code looked like this:
[Test, CustomAttribute]
public void TestName(){
Task.Run(async ()=> await doSomething());
}
TestContext.CurrentContext.Test.Name self corrected after making this change. I have no idea why this worked.