【问题标题】:Run NUnit test fixture programmatically以编程方式运行 NUnit 测试夹具
【发布时间】:2017-07-25 18:00:37
【问题描述】:

我经常想进行快速测试,并在 LINQPad 中编写代码。

所以我有一个Main() 入口点。我可以让 NUnit 从那里以编程方式“运行”一个夹具吗?

using NUnit.Framework;

public class Runner
{

  public static void Main()
  {
    //what do I do here?
  }

  [TestFixture]
  public class Foo
  {

    [Test]
    public void TestSomething()
    {
      // test something
    }

  }

}

【问题讨论】:

    标签: c# nunit


    【解决方案1】:

    您可以使用NUnitLite Runner:

    using NUnit.Framework;
    using NUnitLite;
    
    public class Runner {
    
    
        public static int Main(string[] args) {
            return new AutoRun(Assembly.GetExecutingAssembly())
                           .Execute(new String[] {"/test:Runner.Foo.TestSomething"});
        }
    
        [TestFixture]
        public class Foo {
    
            [Test]
            public void TestSomething() {
                // test something
            }
        }
    
    }

    这里"/run:Runner.Foo"指定了文本夹具。

    请注意,您还必须引用 nunitlite.dll 包。

    【讨论】:

    • There is no argument given that corresponds to the required formal parameter 'testAssembly' of 'AutoRun.AutoRun(Assembly)'
    • 你使用了String[] 数组吗?
    • 嗯...我到了某个地方。现在它抱怨找不到程序集System.Console。我想只有到目前为止我可以推动 LINQPad。虽然它可以在命令行上运行,但它不像 LINQPad 那样友好。我会挖掘一下,看看如何让它发挥作用。
    • @grokky:我再次更改了代码。它是执行程序集。对不起...
    • 我在 LINQPad 中添加了 System.ConsoleSystem.Runtime.InteropServices.RuntimInformation nugets,并添加了您的代码。现在我得到 NUnit 输出,但它不运行夹具:System.PlatformNotSupportedException: Operation is not supported on this platform. 我认为这在 LINQPad 中是不可能的,只有命令行。感谢您帮助我!
    【解决方案2】:

    在 3.8 中,3.7 中引入的问题将得到修复。这是否适用于 LINQPad,我不确定。您可以使用我们的 MyGet 提要中的最新版本进行试用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-04
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      相关资源
      最近更新 更多