我正在使用 Xamarin Studio 5.5,我想在 iOS 模拟器上运行我的测试。 遗憾的是,没有用于创建 iOS 单元测试项目的模板。
最佳答案
- 创建一个空的 F# 项目
将以下文件 (
AppDelegate.fs
) 复制到您新创建的项目中namespace ioslibrarytests //obviously you can choose any namespace you want open System open MonoTouch.UIKit open MonoTouch.Foundation open MonoTouch.NUnit.UI [<Register("AppDelegate")>] type AppDelegate() = inherit UIApplicationDelegate() override val Window = null with get, set override this.FinishedLaunching(app, options) = this.Window <- new UIWindow(UIScreen.MainScreen.Bounds) let runner = new TouchRunner(this.Window) runner.Add (System.Reflection.Assembly.GetExecutingAssembly ()); this.Window.RootViewController <- new UINavigationController (runner.GetViewController ()); this.Window.MakeKeyAndVisible() true module Main = [<EntryPoint>] let main args = UIApplication.Main(args, null, "AppDelegate") 0
创建您的测试文件。例如
Tests.fs
并遵循此实现模式namespace ioslibrarytests open System open NUnit.Framework; [<TestFixture>] type Tests() = [<Test>] member me.Pass() = Assert.True (true) [<Test>] member me.Fail() = Assert.False (true) [<Test>] [<Ignore ("another time")>] member me.``Ignore me``() = Assert.True (false)
请注意
- 您的测试类需要有一个默认构造函数 =>
type Tests() = ...
- 您的测试方法需要有一个空参数列表 =>
member me.Pass() = ...
关于ios - 如何使用 Xamarin 和 F# 在 iOS 上进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27901534/