我正在尝试调用 [OneTimeSetUp],但它没有调用它并直接调用 [TestFixture] SetUp。下面是我正在使用的包
在.NetFramework v4.X中工作正常 **
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
**
namespace Test.BaseClass
{
[SetUpFixture]
public class SetUpClass
{
public static ExtentReports extent;
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
extent = new ExtentReports();
string workingDirectory = Directory.GetCurrentDirectory();
string basedir = Directory.GetParent(workingDirectory).Parent.Parent.FullName;
string path = AppSettings.Settings[$"Log:FileLocation"];
string dir = basedir + path;
var htmlReporter = new ExtentHtmlReporter(dir);
htmlReporter.Config.DocumentTitle = "Automation Testing Report";
htmlReporter.Config.ReportName = "Regression Testing";
htmlReporter.Config.Theme = AventStack.ExtentReports.Reporter.Configuration.Theme.Standard;
extent.AttachReporter(htmlReporter);
extent.AddSystemInfo("Application Under Test", TestContext.CurrentContext.Test.ClassName);
extent.AddSystemInfo("Environment", AppSettings.env);
extent.AddSystemInfo("Machine", Environment.MachineName);
extent.AddSystemInfo("OS", Environment.OSVersion.VersionString);
}
[OneTimeTearDown]
public void RunAfterAnyTests()
{
extent.Flush();
}
}
}
这是[设置]
namespace Test.BaseClass
{
public class BaseTest
{
public static ExtentReports extent;
public ExtentTest test;
[SetUp]
public void StartUpTest()
{
test = SetUpClass.extent.CreateTest(TestContext.CurrentContext.Test.Name);
DriverHelper.InitBrowser();
DriverHelper.BrowserMaximize();
DriverHelper.DeleteAllCookies();
}
[TearDown]
public void AfterTest()
{
try
{
var status = TestContext.CurrentContext.Result.Outcome.Status;
var stacktrace = TestContext.CurrentContext.Result.StackTrace;
var errorMessage = "<pre>" + TestContext.CurrentContext.Result.Message + "</pre>";
Status logstatus;
switch (status)
{
case TestStatus.Failed:
logstatus = Status.Fail;
DateTime time = DateTime.Now;
String fileName = TestContext.CurrentContext.Test.Name;
test.Log(Status.Fail, "Fail");
break;
case TestStatus.Inconclusive:
logstatus = Status.Warning;
break;
case TestStatus.Skipped:
logstatus = Status.Skip;
break;
default:
logstatus = Status.Pass;
break;
}
test.Log(logstatus, "Test ended with " +logstatus + stacktrace);
}
catch (Exception e)
{
throw (e);
}
finally
{
DriverHelper.Close();
}
}
}
}
当我运行测试时,它会跳过 [SetUpFixture] 并直接调用 [TestFixture] 我已经尝试将两者放在单独的命名空间中