NUnit没有运行我的测试用例

时间:2016-09-08 15:07:13

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

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

namespace UnitTests

[<TestFixture>]
module ValidatorTests = 

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

当我尝试在Visual Stuido测试资源管理器中运行它时,没有任何事情发生(即使使用NUnit 3的测试适配器)并且只是说&#34;成功构建&#34;并没有发现任何测试。然后,当我从命令行运行nunit-console runner(尝试使用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#互操作问题?

感谢您的时间:)

1 个答案:

答案 0 :(得分:2)

此修复程序是:

namespace UnitTests

[<TestFixtureAttribute>]
type ValidatorTests () =

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

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