iOS Run UITesting in sequence (file and function level)

[亡魂溺海] 提交于 2020-01-03 02:46:09

问题


I have created UITesting like this. I need to run those 3 file in sequence and I need to name like this. I think it is quite bad. I want to name more logically (instead of Test1,etc). Is it possible to rename and run in sequence?

Another one is I need to name my method alphabetically. I want to name randomly and run in sequence. How shall I do?

- (void)test2CreatePost 
- (void)test3ClickLikeInNewsfeed

回答1:


You could achieve this by nesting your functions.

// Note that this function contains tests but does not follow the 'testXXX' naming convention
func login() {
    // Implement your test here
}

func newsfeed() {
    // Implement your test here
}

func moreTab() {
    // Implement your test here
}

// Here is the test method that will run the tests in a user-specified order
func testSomething() {
    login()
    newsfeed()
    moreTab()
}



回答2:


Functions nesting is fine for running UI tests from XCode instantly only. But when tests are running from command line, they are running by the alphabetic sequence. I've read that this issue was fixed for unit tests in XCode 8, but it seems not for UI tests.

For instance, now I have the following UI tests hierarchy:

UITests
   TestCaseB
   TestCaseA

When I run them from XCode 8.2.1 they are executed in the same sequence as they are described, i.e.:

TestCaseB
TestCaseA

But when I run them from command line using xcodebuild test TEST_TARGET_NAME=<TargetName> -scheme <UITestsSchemeName> destination 'platform=iOS Simulator,name=iPhone 7' they are running in another sequence:

TestCaseA
TestCaseB

Be careful.




回答3:


You can use the procedure explained in this answer to achieve this.

Running individual XCTest (UI, Unit) test cases for iOS apps from the command line

Basically you need to override testInvocations present in XCTestCase, then you have control over the order of test case execution.

If you need more information on how to achieve this add a comment.



来源:https://stackoverflow.com/questions/37154855/ios-run-uitesting-in-sequence-file-and-function-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!