C# 在BeforeTestRun钩子中初始化一个类,并在BeforeTestRun场景中使用它
我在specflow单元测试中使用扩展数据块报告。 我有两个项目在一个解决方案。我有一个单独的项目来创建一个钩子文件,这两个项目都是通用的。 我需要在C# 在BeforeTestRun钩子中初始化一个类,并在BeforeTestRun场景中使用它,c#,unit-testing,specflow,C#,Unit Testing,Specflow,我在specflow单元测试中使用扩展数据块报告。 我有两个项目在一个解决方案。我有一个单独的项目来创建一个钩子文件,这两个项目都是通用的。 我需要在BeforeTestRunhook中初始化我的extentreports对象,并在beforetscenario中使用它。 我没有办法获得同样的信息。 以下是我目前的代码: public static void BeforeFeature() { extentReports = new ExtentReports();
BeforeTestRun
hook中初始化我的extentreports对象,并在beforetscenario
中使用它。
我没有办法获得同样的信息。
以下是我目前的代码:
public static void BeforeFeature()
{
extentReports = new ExtentReports();
htmlReporter = new ExtentHtmlReporter(FeatureContext.Current.FeatureInfo.Title + ".html");
htmlReporter.Configuration().Theme = Theme.Dark;
extentReports.AttachReporter(htmlReporter);
TestcaseConst._logger = LogManager.GetCurrentClassLogger();
FeatureContext.Current.Set<ExtentReports>(extentReports);
}
[BeforeScenario]
public static void BeforeScenario()
{
extentTest = FeatureContext.Current.Get<ExtentReports>().CreateTest(ScenarioContext.Current.ScenarioInfo.Title, "This test is to check the status of API under test");
ScenarioContext.Current.Set<ExtentTest>(extentTest);
}
publicstaticvoidbeforeffeature()
{
extentReports=新的extentReports();
htmlReporter=新的extenshtmlreporter(FeatureContext.Current.FeatureInfo.Title+“.html”);
htmlReporter.Configuration().Theme=Theme.Dark;
extentReports.AttachReporter(htmlReporter);
TestcaseConst.\u logger=LogManager.GetCurrentClassLogger();
FeatureContext.Current.Set(扩展端口);
}
[场景之前]
场景()之前的公共静态无效
{
extentTest=FeatureContext.Current.Get().CreateTest(ScenarioContext.Current.ScenarioInfo.Title,“此测试用于检查测试中API的状态”);
ScenarioContext.Current.Set(extentTest);
}
现在,我需要将BeforeFeature下的代码转换为BeforeTestRun,但我无法在BeforeTestRun中保存类似于“FeatureContext.Current.Set(extentReports);”的内容
如果有人知道,请帮忙。
提前谢谢