多个类的Nunit范围报告未正确报告

时间:2019-05-14 09:59:11

标签: c# nunit extentreports

我为多个类别配置了带范围报告4的Nuit测试。我正在正确获取第一类的范围报告结果,但未报告第二类状态(一次仅报告一个类)

这是为ExtentReprot创建的类<​​/ p>

namespace ReportTestProject
    {
    [TestFixture]
    public class SetupFixture1
    {
        public static ExtentReports _extent;
        public static ExtentTest _test;

    [OneTimeSetUp]
    public void StartReport()
    {
        _extent = new ExtentReports();
        var dir = AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug", "");
        DirectoryInfo di = Directory.CreateDirectory(dir + "\\Test_Execution_Reports");
        var htmlReporter = new ExtentHtmlReporter(dir + "\\Test_Execution_Reports" + "\\Automation_Report" + ".html");
        _extent.AddSystemInfo("Environment", "DEV");
        _extent.AddSystemInfo("User Name", "RAKESH");
        _extent.AttachReporter(htmlReporter);

        _test = _extent.CreateTest(TestContext.CurrentContext.Test.Name);
    }

    [TearDown]
    public void aftertest()
    {
        var status = TestContext.CurrentContext.Result.Outcome.Status;
        var stacktrace = "" + TestContext.CurrentContext.Result.StackTrace + "";
        var errorMessage = TestContext.CurrentContext.Result.Message;
        Status logstatus;

        switch (status)
        {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                _test.Log(logstatus, "Test " + logstatus + " – " + errorMessage + stacktrace);
                break;
            default:
                logstatus = Status.Pass;
                _test.Log(logstatus, "Test " + logstatus);
                break;
        }
    }

    [OneTimeTearDown]
    public void AfterClass()
    {
        _extent.Flush();
    }
    }
}

这是我的第一堂课

namespace ReportTestProject
{
    [TestFixture]
    public class TestClass1 : SetupFixture1
    {
        [Test]
        public void PassTest1()
        {
            _test = _extent.CreateTest("PassTest1");
            var answer = 42;
            Assert.That(answer, Is.EqualTo(42), "Some useful error message");
        }

        [Test]
        public void FailTest1()
        {
            _test = _extent.CreateTest("FailTest1");
            var answer = 43;
            Assert.That(answer, Is.EqualTo(42), "answer is not 42 so test failed");
        }
    }
}

第二班

namespace ReportTestProject
{
    [TestFixture]
    public class TestClass : SetupFixture1
    {
        [Test]
        public void PassTest2()
        {
            _test = _extent.CreateTest("PassTest2");
            var answer = 42;
            Assert.That(answer, Is.EqualTo(42), "Some useful error message");
        }

        [Test]
        public void FailTest2()
        {
            _test = _extent.CreateTest("FailTest2");
            var answer = 43;
            Assert.That(answer, Is.EqualTo(42), "answer is not 42 so test failed");
        }
    }
}

问题是,“范围”报告仅显示测试类1的结果。请参见下面的屏幕截图

enter image description here

我在这里做错了。请帮助

1 个答案:

答案 0 :(得分:0)

尝试在AssemblySetup类中编写OneTimeTearDown方法。

[SetUpFixture]
    public class AssemblySetup
    {
        [OneTimeSetUp]
        public static void Setup()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("de-AT");

        }


        [OneTimeTearDown]
        public void EndReport()
        {
              _extent.Flush();
         }
    }