gpt4 book ai didi

uikit - 从 NUnit 测试代码创建 iOS UI 组件

转载 作者:行者123 更新时间:2023-12-04 16:02:20 26 4
gpt4 key购买 nike

我正在尝试为一些以编程方式创建 UIButton 的代码编写单元测试,但是当我从测试中调用此代码时,我得到了 NullReferenceException .在调试器中单步执行,看起来像 UIButton.FromType()返回空值。

这是我正在测试的方法:

    public UIButton makeButton (String title, Action<IWelcomeController> action)
{
UIButton button = UIButton.FromType (UIButtonType.RoundedRect);
// button is null here
button.SetTitle(title, UIControlState.Normal);
button.TouchUpInside += (sender, e) => {
action(controller);
};
return button;
}

这是测试方法:
    [Test()]
public void TestMakeButtonTitle ()
{
String title = "Elvis";
UIButton button = GetFactory().makeButton(title, delegate(IWelcomeController w) {});
Assert.AreEqual(title, button.Title(UIControlState.Normal));
}

我猜我需要在环境方面做一些魔法才能让 MonoTouch.UIKit 在真实应用程序之外工作。任何提示? (如果不可能,建议的替代方法?)

最佳答案

在这一点上可以肯定,根本问题是,如果您不是在 iPhone 或 iPhone 模拟器上运行,则无法调用必要的 native API 来实例化组件。

也许有一天有人会为 Monotouch 编译 NUnit 并编写一个 iOS 测试运行程序......

关于uikit - 从 NUnit 测试代码创建 iOS UI 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3877057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com