TestResult class - How to instantiate for current run?

463 views Asked by At

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?

0

There are 0 answers