Reputation: 612
All information I read regarding C# entry point class relate to:
static int Main(string[] args)
As this is specific to an EXE program.
But my program is a C# Automation Test framework (.cs within the solution), designed with Specflow feature files and step definitions.
I have now added an (entry point) class called Program.cs - Int Main class but I’ve noticed that this entry point class is not called any time when running my automation tests. Most likely because my program is not an EXE program but a Test framework.
How can I find the C# entry point for Non exe program?
As I want to use utilise my 'Reporting' code from one class that will be called every time I run a test:
namespace Project.Core
{
public class Program
{
public static int Main(string[] args)
{
Adapter.DefaultSearchTimeout = 5000;
int error;
try
{
error = TestSuiteRunner.Run(typeof (Program), Environment.CommandLine);
}
catch (Exception e)
{
TestReport.Setup(ReportLevel.Debug, "myReport.rxlog", true);
Report.Screenshot();
throw new ApplicationException("Error Found", e);
}
return error;
}
}
}
Upvotes: 1
Views: 849
Reputation: 612
As my project is using both MsTest and the Ranorex API I cannot be sure what aspect of the project is being initialised before/during a test run. So I have decided to add the Try/Catch code structure directly into every Step Defintion method in my project.
Try()
{
// code
}
Catch (Exception e)
{
TestReport.Setup(ReportLevel.Debug, "myReport.rxlog", true);
Report.Screenshot();
throw new ApplicationException("Error Found", e);
}
And I can easily move the Catch code into a helper class so that I only have one instance of the code being used through my project:
catch (Exception)
{
WpfHelpers.ExtensionMethods.CatchException(null);
}
Helper class:
public static class ExtensionMethods
{
public static void CatchException(SystemException e)
{
TestReport.Setup(ReportLevel.Debug, "myReport.rxlog", true);
Report.Screenshot();
throw new ApplicationException("Error Found", e);
}
}
Note that I am using this structure so that I can utilise the Report.Screenshot functionality of Ranorex when a failure occurs.
Upvotes: 0
Reputation: 10862
Non-exe projects (i.e. DLLs) have no entry-point. They are APIs that are called by other processes, which have their own entry-points.
You should research the appropriate "before test" methodology for the test framework you are using with SpecFlow. For example in MSTest, such code would go in a method with a signature of:
[TestInitialize]
public void TestInitialize()
{
// Your code
}
Upvotes: 4