测试

时间:2016-03-29 01:16:08

标签: ios swift unit-testing nsundomanager

我正在努力向使用undoManager的Swift库添加一些测试。在图书馆的演示中,将以下打印件添加到viewDidAppear:会导致打印NSUndoManagerObject

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    print(undoManager)
}

我为测试编写了另一个ViewController,当我在ViewController的viewDidAppear:中有相同的代码时,会打印nil

我正在使用以下代码为测试创建ViewController:

override func setUp() {
    super.setUp()

    // Put setup code here. This method is called before the invocation of each test method in the class.
    let storyboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType))

    viewController = storyboard.instantiateInitialViewController() as! ViewController
    viewController.viewDidLoad()
    viewController.viewDidAppear(false)

    // Test and Load the View at the Same Time!
    XCTAssertNotNil(viewController.view)
}

我在ViewController的becomeFirstResponder()内调用viewDidLoad:

我想测试使用默认undoManager的逻辑,所以我需要找出它为nil的原因。我已尝试为默认undoManager分配NSUndoManager的新实例,但它只是一个只读属性。

如果您对查看代码感兴趣,可以使用Github repository

0 个答案:

没有答案