I need one consolidated extent report for my C# Nunit Framework. Following are my classes and code and explanations:
Base Class: Has the extent report setup [Version - 5.0.1], NUnit [version - 3.14.0], NUnit3TestAdapter [Version - 4.5.0]
[SetupFixture]
public abstract class ExtentReportClass
{
protected ExtentReports _extent;
protected ExtentTest _test;
[OneTimeSetUp]
public void CreateClient()
{
try
{
string dir = TestContext.CurrentContext.TestDirectory + "\\Reports\\";
var fileName = this.GetType().ToString() + ".html";
var htmlReporter = new ExtentSparkReporter(dir + fileName);
_extent = new ExtentReports();
_extent.AttachReporter(htmlReporter);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
[OneTimeTearDown]
protected void OneTimeTearDownTest()
{
try
{
_extent.Flush();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
[SetUp]
public void BeforeTest()
{
try
{
string testName = TestContext.CurrentContext.Test.MethodName;
_test = _extent.CreateTest(testName);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
[TearDown]
public void AfterTest()
{
try
{
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(Status.Fail, "Fail");
_test.Log(logstatus, "Test ended with " + logstatus + errorMessage + stackTrace);
break;
case TestStatus.Inconclusive:
logstatus = Status.Warning;
_test.Log(logstatus, "Test ended with " + logstatus);
break;
case TestStatus.Skipped:
logstatus = Status.Skip;
_test.Log(logstatus, "Test ended with " + logstatus);
break;
default:
logstatus = Status.Pass;
_test.Log(logstatus, "Test ended with " + logstatus);
break;
}
//_test.Log(logstatus, "Test ended with " + logstatus + stacktrace);
_extent.Flush();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}}
Test Classes: I have 25 Separate Test Classes having 1-3 Test methods in each
[TestFixture] public class Test1: ExtentReportClass {
[TearDown]
public void DeletDocument()
{
//code//
}
[Test, Description("Desc")]
public void testMethod1()
{
//Code//
}}}
Not every test class has teardown and setup, some do.
Whenever I am running the whole suite, only one extent report is getting created for the last test method/s for the last test class. I need all the methods result consolidated in one html file format. What should I do? P.S. I have already tried seprate class for [Setup]/[Teardown] and inheriting them, but nothing worked. Any help will be appreciated. Thanks in advance! enter image description here