1)UI執行方式如下:
a、直接點擊每個test example 前面的菱形可單獨執行特定用例;
b、在“show the test navigator”下可以點擊播放按鈕制定測試用例類下的全部測試用例;
c、使用command+U執行全部測試用例。
2)使用命令執行測試用例:
xcodebuild 測試target名 -scheme 工程scheme名 -destination ‘platform=iOS Simulator,name=iPhone 6s Plus’
Ps: 如果執行報錯為:No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=armv7),那么需要修改testtarget 的屬性(包括:修改testtarget中build settings下的build active architecture only改為no,同時valid architects添加 armv7 和arm64(與工程保持一致,$(ARCHS_STANDARD)))。
a、首先在product->scheme->Edit Scheme里面,選中test工程,將Code Coverage模式打開;
b、執行測試用例;
c、打開Xcode左邊窗口的Report Navigator(圖標類似微信聊天氣泡),找到 Project Log,選擇這個Log實例,并選擇coverage能看到代碼覆蓋率匯總數據;
原文轉自:http://tmq.qq.com/2017/07/ios/