【问题标题】:NUnit Test project not finding any testsNUnit 测试项目没有找到任何测试
【发布时间】:2016-04-19 01:31:42
【问题描述】:

我是 NUnit 测试的新手,由于某种原因,在尝试设置全局变量时,程序丢失了对所有测试的所有引用。我认为这是因为我试图以错误的方式创建全局变量。任何正确方向的提示都会有所帮助。

这里是代码片段。

using System;
using JMS;
using System.IO;
using NUnit.Framework;

namespace JMSTest {

    [TestFixture]
    public class JMSTests {

    private JMSForm testJMS { get { return new JMSForm(); } }
    private string[] goodFileList = new string[] { ".DLD", ".STA", ".TIF", ".DFC", ".PDF" };
    private string[] ignoreFileList = new string[] { ".INI", ".RBK" };
    
    [Test]
    public void TestCreateConnectionStringBlank() {
        string testString = testJMS.createConnectionString("", "", "", "");

        Assert.AreEqual(testString, "server=;database=;uid=;password=");
    }

    [Test]
    public void TestCreateConnectionStringProper() {
        string testString = testJMS.createConnectionString("1", "2", "3", "4");

        Assert.AreEqual(testString, "server=1;database=2;uid=3;password=4");
    }

我得到的结果是:

------发现测试开始-----

========== 发现测试已完成:找到 0 个 (0:00:00.037) ==========

我也试过

public class JMSTests {

    private static JMSForm testJMS;
    private static string[] goodFileList;
    private static string[] ignoreFileList;

    [SetUpFixture]
    public class before_tests_run {
        [SetUp]
        public void ControllerASetup() {
            var testJMS = new JMSForm();
            var goodFileList = new string[] { ".DLD", ".STA", ".TIF", ".DFC", ".PDF" };
            var ignoreFileList = new string[] { ".INI", ".RBK" };
        }
    }

【问题讨论】:

  • 如果您已经得到的答案没有帮助,那么回来并准确说明您使用的 NUnit 版本以及您安装的测试适配器。

标签: c# global-variables nunit


【解决方案1】:

如果您使用的是NUnit3+ 版本,则可以使用新的测试适配器。 去

Tools -> Extensions and Updates -> Online”并搜索“NUnit3 Test 适配器

然后安装它。然后你就可以运行测试了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多