1

For context, I am using NUnit with Selenium, for GUI web testing. I am using NUnit for control flow to ensure there are setup and teardown steps before each test.

I have a method that builds a basic log file:

public class TestMetaData
{
    public Test Test;

    private readonly TestResult testResult;

    public TestMetaData()
    {
        Test = TestExecutionContext.CurrentContext.CurrentTest;
        testResult = Test.MakeTestResult();
    }

    public string BuildBasicLog(Test test)
    {
        var currentLog = $"Current Test Name: {Test.MethodName}\r\n" + $"Test Result: {testResult.ResultState}\r\n" + $"Run Duration: {testResult.Duration.ToString(CultureInfo.CurrentCulture)}";

        return currentLog;
    }
}

The output is populating the methodName accurately, so I am under the impression the instantiation of Test is picking up the current test that is executing, but, the Result state is ALWAYS Inconclusive and the duration is ALWAYS 0.

Can anyone shed light on what's going wrong here?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
  • check the following answer and see if it applies to your problem https://stackoverflow.com/a/5241900/5233410 – Nkosi May 18 '18 at 13:55
  • Many thanks for reformatting the post and for this pointer. I'm afraid I am not using the Nunit runner when executing my tests. Nunit is only really being used for the control flow between 2 classes with the TestFixture attribute. The referenced answer seems to instantiate the TestResult object from a current instance of the runner. I don't have the runner to do that with. So as you see above I instantiate it using the ITest object from the CurrentExecutionContext. Perhaps I am missing something here though? – Joe Triccas May 18 '18 at 15:56
  • I know that the TEST object that gets derived from the CurrentExecutionContext is relevant to the currently executing test because I am consuming the Test.Test.MethodName in log files and screen shots that this solution is outputting – Joe Triccas May 18 '18 at 15:58

0 Answers0