【问题标题】:NUnit is not running my test casesNUnit 没有运行我的测试用例
【发布时间】:2017-01-16 14:14:22
【问题描述】:

我有一个看起来像这样的测试用例:

namespace UnitTests

[<TestFixture>]
module ValidatorTests = 

    [<Test>]
    let VerifyBasicFunctionality () = 
        Assert.That(bool)
        Assert.That(bool)

当我尝试在 Visual Stuido 测试资源管理器中运行它时,什么也没有发生(即使使用 NUnit 3 的测试适配器),只是说“成功构建”并且没有发现任何测试。然后,当我使用 nunit-console 运行器从命令行运行(尝试使用 v.1、v.2、v.4)时,我得到了一些不同的东西:

$ nunit-console4 bin/Release/UnitTests.dll
NUnit version 2.4.8
Copyright (C) 2002-2007 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment - 
   OS Version: Unix 15.6.0.0
  CLR Version: 4.0.30319.42000 ( 4.4.2 (Stable 4.4.2.11/f72fe45 Thu Aug 11 06:03:25 BST 2016) )

.N.N.N
Tests run: 0, Failures: 0, Not run: 3, Time: 0.011 seconds

当我使用 -xmlConsole 标志运行它时,我得到了这个:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--This file represents the results of running a test suite-->
<test-results name="bin/Release/UnitTests.dll" total="0" failures="0" not-run="3" date="2016-09-08" time="10:26:00">
  <environment nunit-version="2.4.8.0" clr-version="4.0.30319.42000" os-version="Unix 15.6.0.0" platform="Unix" cwd="/SOMEUSER/SOMEPATH/UnitTests" machine-name="gmaini-m.jet.local" user="SOMEUSER" user-domain="SOMELOCALBOX" />
  <culture-info current-culture="en-US" current-uiculture="en-US" />
  <test-suite name="bin/Release/UnitTests.dll" success="True" time="0.010" asserts="0">
    <results>
      <test-suite name="UnitTests" success="True" time="0.008" asserts="0">
        <results>
          <test-suite name="ValidatorTests" success="True" time="0.001" asserts="0">
            <results>
              <test-case name="UnitTests.ValidatorTests.VerifyBasicFunctionality" executed="False">
                <reason>
                  <message><![CDATA[UnitTests.ValidatorTests is an abstract class]]></message>
                </reason>
              </test-case>
              <test-case name="UnitTests.ValidatorTests.VerifyBasicOtherFunctionality" executed="False">
                <reason>
                  <message><![CDATA[UnitTests.ValidatorTests is an abstract class]]></message>
                </reason>
               </test-case>
               <test-case name="UnitTests.ValidatorTests.VerifyBasicSomeFunctionality" executed="False">
                <reason>
                  <message><![CDATA[UnitTests.ValidatorTests is an abstract class]]></message>
                </reason>
              </test-case>
            </results>
          </test-suite>
        </results>
      </test-suite>
    </results>

知道为什么它似乎发现了测试,我可以用-run="Namespace.Module.Function" 访问它们并用-fixture="Namespace" 谈论夹具但它不会运行它们? UnitTests.ValidatorTests.VerifyBasicFunctionality is an abstract class 是否暗示存在一些 C# 互操作问题?

感谢您的宝贵时间:)

【问题讨论】:

    标签: unit-testing f# nunit nunit-3.0 nunit-console


    【解决方案1】:

    此修复是:

    namespace UnitTests
    
    [<TestFixtureAttribute>]
    type ValidatorTests () =
    
        [<Test>]
        member __.VerifyBasicFunctionality() =
            Assert.That(bool)
            Assert.That(bool)
    

    基本上,使这个面向对象。所以我的假设是正确的。

    【讨论】:

    • 一个 F# 模块本质上是一个静态类,但是您正在运行的旧(实际上是古老的)NUnit 版本不了解静态类,并且由于 .NET 实现静态类的方式而将其误解为抽象.
    • @Charlie:对,但是 Mono 的 macOS 安装程序带来的是 NUnit 2.4.8 而不是 2.6.4(后者兼容模块,前者不兼容)
    • Mono 安装 2.4.8 是为了它自己的目的(用于构建 Mono)。对于运行测试的用户,你不应该使用它。就此而言,NUnit 2.6.4 也是遗留的。尝试 NUnit 3.10.1。 :-)
    猜你喜欢
    • 2016-10-24
    • 2014-01-03
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多