【问题标题】:NUnit-Console finds no test fixtures for an NUnitForms test with NUnit 3.xNUnit-Console 找不到使用 NUnit 3.x 进行 NUnitForms 测试的测试装置
【发布时间】:2017-05-10 14:02:57
【问题描述】:

我一直在搞乱NUnitForms,我的简单测试遇到了障碍。我将在下面提供更多信息,但简要总结一下这个问题,我处于需要从 NUnitFormTest 类继承才能使用 ExpectModal 功能的状态,但这会导致无法找到测试(使用 NUnit 3.6.1)。如果我降级到NUnit 2.x 版,则可以找到测试,但在 TearDown 函数上出现错误。我这里有什么遗漏吗?

完整信息见下文...

我的测试最初是引用NUnit 3.6.1,如下所示:

using EnterpriseManager;
using NUnit.Extensions.Forms;
using NUnit.Framework;

namespace ManagerTests
{
    [TestFixture]
    public class ManagerTests
    {
        [Test]
        public void ConnectTest()
        {
            ConnectForm form = new ConnectForm();
            form.Show();

            ButtonTester testButton = new ButtonTester("TestConnectionButton", "ConnectForm");
            testButton.Click();

            LabelTester testLabel = new LabelTester("StatusLabel", "ConnectForm");
            Assert.AreEqual("Connection successful", testLabel.Text);
        }
    }
}

在我上面的初始测试中,我没有从 NUnitFormTest 类继承(当时不知道),但即使它丢失了,我的测试也会被 Visual Studio 的测试资源管理器找到并且我可以运行我通过nunit3-console 应用程序进行的测试(通过了)。

最终我扩展了我的测试以调用一个模态对话框,这给我带来了问题,尽管最终我读到了ExpectModal 功能,这导致我添加了NUnitFormTest 继承。测试变成了下面这样:

using EnterpriseManager;
using NUnit.Extensions.Forms;
using NUnit.Framework;

namespace ManagerTests
{
    [TestFixture]
    public class ManagerTests : NUnitFormTest
    {
        [Test]
        public void ConnectTest()
        {
            ConnectForm form = new ConnectForm();
            form.Show();

            ButtonTester testButton = new ButtonTester("TestConnectionButton", "ConnectForm");
            testButton.Click();

            LabelTester testLabel = new LabelTester("StatusLabel", "ConnectForm");
            Assert.AreEqual("Connection successful", testLabel.Text);

            ExpectModal("ConnectToServer", delegate { 
                LabelTester label = new LabelTester("ConnectStatusLabel", "ConnectToServer");
                Assert.AreEqual("Connected", label.Text);
            });

            // Launch the modal dialog
            ButtonTester connectButton = new ButtonTester("ConnectToServerButton", "ConnectForm");
            connectButton.Click();
        }
    }
}

这就是问题的开始。添加NUnitFormTest 类的继承后,Visual Studio 和nunit3-console.exe 均未检测到任何测试。我认为这可能与引用的 NUnit 的版本有关,所以我降级到各种 2.x 版本。这允许 Visual Studio 检测到测试(尽管 nunit3-console.exe 一直报告“不确定”结果),但所有测试都会失败并出现错误:

Result StackTrace:  
--TearDown
at NUnit.Extensions.Forms.Desktop.Destroy()
at NUnit.Extensions.Forms.NUnitFormTest.Verify()
Result Message: TearDown : System.ComponentModel.Win32Exception : The requested resource is in use

我已经围绕这个问题进行了一些搜索,但我发现的所有内容似乎都表明这是以前遇到的 NUnit 的一些问题,在某个时候已修复(不要引用我的话)。所以现在我处于需要从NUnitFormTest 类继承才能使用ExpectModal 功能的状态,但这会导致无法找到测试。然而,如果我降级到NUnit 2.x 版,我会在TearDown 函数上遇到问题。我在这里缺少什么吗?

【问题讨论】:

  • 目前无法尝试,但解决 TearDown 问题的潜在解决方法是覆盖 NUnitFormTest 中的 UseHidden 属性以返回 false。
  • 知道是否有已知方法可以将NUnitFormsNUnit 3.x 一起使用,还是仅适用于2.x 版本?
  • 我不确定,我使用它的年代久远了,看起来它已经有几年没有发布了。

标签: c# nunit nunit-console


【解决方案1】:

NUnitForms 已经很多年没有更新了,所以它仍然依赖于 NUnit V2。当您从 NUnitFormTest 派生时,您使用的是 NUnit 2.6.2,无论您认为自己安装了什么,因为代码与 NUnit 的一个版本紧密耦合。

NUnitForms 可以轻松更新到 NUUnit 2.6.4,但除此之外,这是一个更大的变化,甚至可能需要重写。

顺便说一句,Luke 很久以前就将我添加到该项目中,但我一直不活跃。我曾经希望让它的一个版本与 NUnit 3 一起工作,但我怀疑是否有更多的需求来测试 Windows 窗体。

您应该从您的解决方案中删除 NUnit 框架的所有包,并引用与 NUnitForms 一起安装的版本。如果你想试验不同的版本,它们应该是 NUnitForms 的版本,这样你的测试和 NUnitForms 都引用同一个 NUnit 副本。

【讨论】:

  • 好的,感谢您提供的信息,这为我解决了问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-25
相关资源
最近更新 更多