nunit-console不使用TestCase和TestCaseSource运行测试

时间:2015-02-13 10:04:59

标签: jenkins xamarin nunit nunit-console

我在OSX上使用Xamarin Studio,我已经使用NUnit.Framework实现了一个PCL项目测试套件(没有引用View iOS和Android)。所有这些都可以通过GUI在Xamarin Studio中正常工作(所有测试都已运行且有效)。

现在我试图在Jenkins中集成测试套件执行。当我通过命令行运行我的测试套件(这发生在Jenkins以及我的本地环境中)

 mono /Library/Frameworks/Mono.framework/Versions/3.12.0/lib/mono/4.5/nunit-console.exe Libs/Debug/MyTests.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 14.1.0.0
  CLR Version: 4.0.30319.17020 ( 3.12.0 ((detached/de2f33f Mon Feb  2 14:42:07 EST 2015) )

Tests run: 7, Failures: 0, Not run: 19, Time: 16.530 seconds

有19项测试没有运行这种动机:

<test-suite name="MyTestClass" success="True" time="0.000" asserts="0">
   <results>
      <test-case name="NamespaceExample.MyTestClass.MyTestMethod" description="My Test Description" executed="False">
         <reason>
            <message><![CDATA[Method MyTestMethod's signature is not correct: it must not have parameters.]]></message>
         </reason>
      </test-case>
   </results>
</test-suite>

这种测试有一个共同的特点,就是使用TestCase。实施例

namespace NamespaceExample
{
    [TestFixture]
    public class MyTestClass
    {

        public IMyService service;

        [SetUp]
        public void TestCase()
        {
            // this method will be called before running every test
            service = new MyService ();
        }

        [Test (Description = "My Test Description")]
        [TestCase("it")]
        public void MyTestMethod(string code)
        {
            string terms = service.MethodToTest (code);
            Assert.IsNotNull (terms);
        }
    }
}

似乎nunit-console没有使用TestCase参数运行测试。我也尝试将TestCaseSource与IEnumerable源一起使用,但结果并没有改变。

如果我没有在方法签名中传递此参数,但它设置了内部方法测试已运行且工作正常。

我怎么能解决?

我也读过这类问题Similar Question,但它没有解决,因为结果相同(测试没有运行)。

我的环境是

=== Xamarin Studio ===

Version 5.7.1 (build 17)
Installation UUID: xxx
Runtime:
    Mono 3.12.0 ((detached/de2f33f)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 312000076

=== Apple Developer Tools ===

Xcode 6.0 (6299)
Build 6A313

=== Xamarin.iOS ===

Version: 8.6.1.20 (Indie Edition)
Hash: xxx
Branch: 
Build date: 2015-01-24 09:42:21-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Indie Edition)
Android SDK: xxx/android-sdk-mac_x86
    Supported Android versions:
        1.6    (API level 4)
        2.1    (API level 7)
        2.2    (API level 8)
        2.3    (API level 10)
        3.1    (API level 12)
        4.0    (API level 14)
        4.0.3  (API level 15)
        4.1    (API level 16)
        4.2    (API level 17)
        4.3    (API level 18)
        4.4    (API level 19)
        4.4.87 (API level 20)
        5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin.Mac ===

Not Installed

=== Build Information ===

Release ID: 507010017
Git revision: xxx
Build date: 2015-02-03 19:43:29-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

=== Operating System ===

Mac OS X 10.10.2
Darwin LS.local 14.1.0 Darwin Kernel Version 14.1.0
    Mon Dec 22 23:10:38 PST 2014

1 个答案:

答案 0 :(得分:1)

尝试使用更新的NUnit版本。您正在使用NUnit 2.4.8。 Xamarin Studio内置的NUnit运行程序使用NUnit 2.6.3版本。

看起来NUnit 2.5引入了对TestCase属性的支持。您可以从http://nunit.org/index.php?p=download

下载NUnit