Nunit3 OneTimeSetUp 和 OneTimeTeardown 不起作用

问题描述 投票:0回答:2

OneTimeSetUp 和 OneTimeTearDownStopped 工作

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{

    class Class1
    {
        [SetUp]
        public void setup()
        {
            Console.WriteLine("setup method");
        }
        [TearDown]
        public void teardown()
        {
            Console.WriteLine("teardown");
        }
        [OneTimeSetUp]
        public void onetimesetup()
        {
            Console.WriteLine("onetimesetup method");
        }
        [OneTimeTearDown]
        public void onetimeteardown()
        {
            Console.WriteLine("onetimeteardown method");
        }
        [Test]
        public void testCase()
        {
            Console.WriteLine("Testcase method 2");
        }

    }
}

我之前安装了Resharper,现在我已经完成了resharper。 我已从 C:\Users kris\AppData\Local\Microsoft\VisualStudio 删除 resharper .0_d20cab45\扩展 而且我现在更多地将它放在控制面板中。

但我仍然有这个问题。我之前有一个项目运行良好。这是我从 nuget 包下载的包。 更准确地说,请找到我正在尝试完成的项目

https://github.com/vkrishna92/AutomationProjects/blob/master/SeleniumAutomationDemoQA/SeleniumAutomationDemoQA/Utitlities/OneTimeClass.cs

enter image description here

c# selenium nunit nunit-3.0
2个回答
1
投票

TestFixture 没有任何问题(例如,这里有一个类似的问题),所以肯定是测试运行方式有问题,所以让我为您提供另一种运行测试的方法......

  1. 获取 NUnit.Console NuGet 包(这包括另一个名为 NUnit.ConsoleRunner 的包,稍后会提到)。
  2. 选择包含要运行的单元测试的项目。
  3. 转到该项目的项目属性。
  4. 转到“应用程序”选项卡。
  5. 选择程序集名称并将其复制到剪贴板。
  6. 转到“调试”选项卡。
  7. 在“启动选项”/“命令行参数:”中粘贴程序集名称并在末尾添加“.dll --debug --inprocess”。
  8. 将“工作目录”更改为构建 DLL 的文件夹。
  9. 将“启动操作”设置为“启动外部程序”,并给出 NUnit 控制台的位置(例如 “完整路径\NUnit.ConsoleRunner.版本工具 unit3-console.exe”)。
  10. 在“解决方案资源管理器”中,右键单击该项目并选择“设置为启动项目”。
  11. 然后从 Visual Studio 中“启动”解决方案

希望这有帮助。


0
投票

在我的例子中,包含 [OneTimeSetUp] 的文件应该位于测试项目文件夹的根目录中。

© www.soinside.com 2019 - 2024. All rights reserved.