I have created a POM framework using NUnit in C#. I have created Reporting.cs file which creates reports for the test in that class. How I can generate reports for all tests in different classes without rewriting the reporting code.
BaseTest
– References
– package
– config
– projects
|- project_name
|- pages
|- tests
|- utils
|- reporting.cs
In tests folder files with TestLoginModule.cs have functions
[Test]
public void TestFirst()
{
// test code
}
[Test]
public void TestSecond()
{
// test code
}
In tests folder files with TestDashboardModule.cs have functions
[Test]
public void TestThird()
{
// test code
}
[Test]
public void TestFourth()
{
// test code
}
In Reporting.cs file
[OneTimeSetUp]
public void BeforeClass()
{
// create a test report directory and attach reporter
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.AttachReporter(htmlReporter);
}
[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 ended with” + logstatus + “-” + errorMessage);
test.Log(logstatus, “screenshot”);
break;
case TestStatus.Skipped:
logstatus = Status.Skip;
break;
default:
logstatus = Status.Pass;
break;
}
SB.Driver.Close();
SB.Driver.Quit();
}
[OneTimeTearDown]
public void AfterClass()
{
extent.Flush();
}
I want to call Reporting.cs OneTimeSetUp and TearDown after every Test in different files
Source: Read More