Ordering unit test using XCTest in Xcode 6

后端 未结 7 1360
眼角桃花
眼角桃花 2020-12-24 12:37

I would like to know if there is any way to tell Xcode to run unit tests in a specified order. I mean not in a same XCTestCase class file, but between all the class file.

7条回答
  •  醉梦人生
    2020-12-24 13:23

    Since Xcode 7, XCTestCase subclasses are alphabetically ordered. If you want to ensure that the test methods themselves are also run in alphabetical order, you must override the testInvocations class method and return the invocations sorted by selector.

    @interface MyTestCase : XCTestCase
    @end
    
    @implementation MyTestCase
    
    + (NSArray *) testInvocations
    {
        return [[super testInvocations] sortedArrayUsingComparator:^NSComparisonResult(NSInvocation *invocation1, NSInvocation *invocation2) {
            return [NSStringFromSelector(invocation1.selector) compare:NSStringFromSelector(invocation2.selector)];
        }];
    }
    
    - (void) test_01
    {
    }
    
    - (void) test_02
    {
    }
    
    @end
    

提交回复
热议问题