【发布时间】:2020-05-05 22:36:29
【问题描述】:
我正在 Visual Studio 测试资源管理器中执行一些写入日志文件的测试(我正在使用 Serilog)。目前,每次我的 BaseTest 执行LoggingFactory.InitializeLoggingFactory()它都会创建一个新的日志文件,因此每个测试类都有多个日志。如何在全局范围内调用 LoggingFactory.InitializeLoggingFactory() 以便每次执行所有测试都可以得到 1 个日志文件?
abstract class BaseTest
{
protected static IWebDriver driver;
protected static WebDriverWait wait;
protected static Actions actions;
protected static ExcelDataFactory excelDataFactory;
[OneTimeSetUp]
public void startLogger()
{
LoggingFactory.InitializeLoggingFactory();
}
[SetUp]
public void Initialize()
{
driver = new Browser().ConfigureBrowser(MyProps.Default.Browser);
wait = new WebDriverWait(driver, TimeSpan.FromSeconds(MyProps.Default.TimeOut));
actions = new Actions(driver);
excelDataFactory = new ExcelDataFactory();
ScreenshotFactory.SetDriverForScreenshot(driver);
ExceptionTracker.RemoveAllExceptions();
}
[TearDown]
public void CleanUp()
{
ExceptionTracker.PrintAllExceptions();
if (driver != null)
{
driver.Close(); // Close the chrome window
driver.Quit(); // Close the console app that was used to kick off the chrome window
driver.Dispose(); // Close the driver.exe
}
}
}
【问题讨论】: