我必须首先要说的是,由于我是Xamarin的新手,我不确定如何表达这些问题。
我正在Xamaring构建应用程序,目的是成为跨平台。
以下是步骤:
Demo.UI.TestHarness.iOS
,输入:iOS统一单位测试应用Demo.UnitTests
,类型:跨平台可移植库Demo.UI.TestHarness.iOS
启动项目NUnitLite
添加到Demo.UnitTests
Demo.UnitTests
Demo.UI.TestHarness.iOS
的引用
醇>
这样做了,我在Demo.UnitTests
创建了一个DummyTest类:
using System;
using NUnit.Framework;
namespace Demo.UnitTests
{
[TestFixture]
public class DummyTest
{
[Test]
public void DUMMY ()
{
Assert.True (false);
}
}
}
我在UnitTestAppDelegate
的{{1}}文件中添加了对此Demo.UI.TestHarness.iOS
的引用:
DummyTest
现在,我可以构建项目并运行调试器模拟,但不会显示任何测试。
如果我直接在我的using System;
using System.Linq;
using System.Collections.Generic;
using Foundation;
using UIKit;
using MonoTouch.NUnit.UI;
using Demo.UnitTests;
namespace Demo.UI.TestHarness.iOS
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register ("UnitTestAppDelegate")]
public partial class UnitTestAppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
TouchRunner runner;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
runner = new TouchRunner (window);
// register every tests included in the main application/assembly
// runner.Add (System.Reflection.Assembly.GetExecutingAssembly ());
runner.Add(typeof(DummyTest).Assembly);
window.RootViewController = new UINavigationController (runner.GetViewController ());
// make the window visible
window.MakeKeyAndVisible ();
return true;
}
}
}
项目中添加DummyTest
并完全忘记Demo.UI.TestHarness.iOS
项目,它会按预期运行(但这不是我想要的,因为我想要将所有测试结合在一起,以便稍后对Android和Mac使用相同的测试,而不必为每个平台重做它们。)
答案 0 :(得分:1)
任何人都想知道为什么这不起作用 - 这是我的研究引导我: https://forums.xamarin.com/discussion/16909/cant-test-pcl-test-assembly-from-xamarin-android-nunitlite-or-monotouch-nunit-ui
特别是" Seb Bartholomew"的帖子。在他的回复中,他发布了一个工作(我还没有尝试过)。基本问题是:
Xamarin.iOS使用MonoTouch.NUnitLite,Xamarin.Android使用Xamarin.Android.NUnitLite,而PCL使用基础NUnit nuget包。
虽然程序集具有相同的名称并且属于相同的名称空间,但它们是完整的不同类型,因此Monotouch测试运行器不会检测外部[Test]属性。