I am trying to write unit test for some code that programmatically creates UIButtons, but when I call this code from the test, I get a NullReferenceException . In the debugger, it looks like this: UIButton.FromType() returns null.
Here is the method I'm testing:
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; }
And here is the test method:
[Test()] public void TestMakeButtonTitle () { String title = "Elvis"; UIButton button = GetFactory().makeButton(title, delegate(IWelcomeController w) {}); Assert.AreEqual(title, button.Title(UIControlState.Normal)); }
I guess there is some kind of magic that I need to do from an environmental point of view in order to get MonoTouch.UIKit to work outside of the real application. Any hints? (And if this is not possible, alternative approaches are proposed?)
David moles
source share