我阅读的有关 C# 入口点类的所有信息都涉及:
static int Main(string[] args)
因为这是特定于 EXE 程序的。
但我的程序是一个 C# 自动化测试框架(解决方案中的 .cs),使用 Specflow 功能文件和步骤定义设计。
我现在添加了一个名为 Program.cs - Int Main 类的(入口点)类,但我注意到在运行我的自动化测试时,这个入口点类在任何时候都不会被调用。很可能是因为我的程序不是 EXE 程序而是测试框架。
如何找到非 exe 程序的 C# 入口点?
因为我想使用我每次运行测试时都会调用的一个类中的“报告”代码:
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;
}
}
}
请您参考如下方法:
非 exe 项目(即 DLL)没有入口点。它们是由其他进程调用的 API,这些进程有自己的入口点。
您应该为与 SpecFlow 一起使用的测试框架研究适当的“测试前”方法。例如在 MSTest 中,这样的代码将进入一个签名为:
[TestInitialize]
public void TestInitialize()
{
// Your code
}
