UI Testing in Xcode 7

参考文章:

UI Testing in Xcode - WWDC 2015
https://developer.apple.com/videos/play/wwdc2015-406/

Document

https://developer.apple.com/library/prerelease/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/UnitTesting.html

UI Testing in Xcode 7 revised
https://testerhome.com/topics/3372

UI Testing in Xcode 7
http://masilotti.com/ui-testing-xcode-7/

UI Testing Cheat Sheet and Examples
http://masilotti.com/ui-testing-cheat-sheet/

XCTest Reference
http://masilotti.com/xctest-documentation/index.html

 

1. 点击Test navigator icon,切换到Test模块

 

2. 点击左下角的“+”号,可以选择添加 Unit test target、Unit test class、UI test target、UI test class

这里我们选择 UI test target

 

如上图:

HouseLoanCalTests 是 Unit Test

HouseLoanCalUITests 是 UI Test

3.  

 

 

 

 

问题1:

XCTAssertEqual(periodTextField.value, @"1");

XCTAssertTrue([periodTextField.value isEqualToString:@"1"], @"Strings are not equal %@ %@", @"1", periodTextField.value);

用 XCTAssertEqual,这个判断需要两个对比元素都是C类型(scalars、struct、union等),如xx.count,可以用XCTAssertEqual;

解决方法:

换成 XCTAssertTrue

http://stackoverflow.com/questions/19464261/xctassertequal-fails-to-compare-two-string-values

 

问题2:

之前给四个页面分别写了一个test,原本是向顺序执行的,但是发现运行时每个test都会调起一次app

解决方法:

之前在 setUp 方法里写了 [self.app launch],将之移到第一个test里面即可;

 

问题3:

在公司app里添加了一个xxxUITests,运行失败

解决方法:

1. Edit Scheme,Test项选择为OL

2. 错误:Tests couldn’t be loaded because it doesn’t contain a version for the current architecture

No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386).

选择 Build Settings 里面 Valid Architectures 里,原来只有arm7、arm7s,这里需要加上arm64

 

问题4:

新建UITest的方法有好几种

1. 切换到test模块,点击左下角的+,New UI Test Target

2. File - New - Target - Test - iOS UI Testing Bundle

新建完的target,从代码目录看,是有个xxxUITests.m文件的,但是从test模块看,下面的test数目是0,且那个xxxUITests.m文件里的系统函数没有高亮

目前没有找到根本原因,零时的解决方法是:运行一下这个UI testing,试了几遍之后,就有了

 

posted @ 2015-10-08 10:14  mobilefeng  阅读(515)  评论(0编辑  收藏  举报