简体   繁体   中英

iOS Run UITesting in sequence (file and function level)

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

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()
}

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, ie:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM