How can I use both KIF and XCTest in one test case class?

316 views Asked by At

I'm trying to adapt this solution for resetting application after each test in my KIF test class. So I modified main.m file and added

XCUIApplication *app = [[XCUIApplication alloc] init];
app.launchArguments = @[@"--reset-container"];
[app launch];

into Setup{} block

Then I run tests on simulator and immediately catch exception in Setup block:

"NSInternalInconsistencyException", "No target application path specified via test configuration: XCTestConfiguration: 0x600000141600

Error log:

file:///Users/user/Documents/GIT/Projects/MyProject/UnitTests/Case01AuthorizationTests.m: test failure: -[authorizationTests test08ValidLogin] failed: failed: caught "NSInternalInconsistencyException", "No target application path specified via test configuration: <XCTestConfiguration: 0x600000141600>
                      testBundleURL:file:///Users/user/Library/Developer/Xcode/DerivedData/MyPoject-edjreexihtzcqyefoinanbbogxhm/Build/Products/Debug-iphonesimulator/%D0%A2%D0%B0%D0%BA%D1%81%D0%BA%D0%BE%D0%BC%20%D0%9A%D0%B0%D1%81%D1%81%D0%B0.app/PlugIns/UnitTests.xctest/
             testBundleRelativePath:(null)
                  productModuleName:UnitTests
                        testsToSkip:authorizationTests/test05CheckPassword, authorizationTests/test04CheckLoginFields, authorizationTests/test01CheckMainServer, authorizationTests/test06WrongPassword, authorizationTests/test03CheckEmail, authorizationTests/test02CheckTestServer
                         testsToRun:authorizationTests
                 reportResultsToIDE:YES
                  sessionIdentifier:440A6681-2527-4286-B232-65126E740F22
         pathToXcodeReportingSocket:(null)
          disablePerformanceMetrics:no
    treatMissingBaselinesAsFailures:no
                    baselineFileURL:(null)
           baselineFileRelativePath:(null)
              targetApplicationPath:(null)
          targetApplicationBundleID:(null)
         targetApplicationArguments:(null)
       targetApplicationEnvironment:
(null)
                   reportActivities:no
           testsMustRunOnMainThread:no
             initializeForUITesting:no
     aggregateStatisticsBeforeCrash:{
    XCSuiteRecordsKey =     {
    };
}
            automationFrameworkPath:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Developer/Library/PrivateFrameworks/XCTAutomationSupport.framework
                         emitOSLogs:no
"
(
    0   CoreFoundation                      0x000000010546db0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000104b62141 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000105471cf2 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x0000000102a7f536 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
    4   XCTest                              0x000000011517bc58 -[XCUIApplication init] + 202
    5   UnitTests                           0x00000001166afb9f -[authorizationTests setUp] + 143
    6   XCTest                              0x000000011515579a __24-[XCTestCase invokeTest]_block_invoke_2 + 163
    7   XCTest                              0x0000000115193f62 -[XCTestContext performInScope:] + 190
    8   XCTest                              0x00000001151556e4 -[XCTestCase invokeTest] + 254
    9   XCTest                              0x0000000115155fb2 -[XCTestCase performTest:] + 565
    10  XCTest                              0x0000000115153078 __27-[XCTestSuite performTest:]_block_invoke + 300
    11  XCTest                              0x0000000115152c68 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 29
    12  XCTest                              0x0000000115152e4e -[XCTestSuite performTest:] + 214
    13  XCTest                              0x0000000115153078 __27-[XCTestSuite performTest:]_block_invoke + 300
    14  XCTest                              0x0000000115152c68 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 29
    15  XCTest                              0x0000000115152e4e -[XCTestSuite performTest:] + 214
    16  XCTest                              0x0000000115153078 __27-[XCTestSuite performTest:]_block_invoke + 300
    17  XCTest                              0x0000000115152c68 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 29
    18  XCTest                              0x0000000115152e4e -[XCTestSuite performTest:] + 214
    19  XCTest                              0x000000011519fa86 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 40
    20  XCTest                              0x0000000115161f27 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 574
    21  XCTest                              0x000000011519f925 -[XCTTestRunSession runTestsAndReturnError:] + 281
    22  XCTest                              0x000000011513da50 -[XCTestDriver runTestsAndReturnError:] + 254
    23  XCTest                              0x000000011519786e _XCTestMain + 559
    24  CoreFoundation                      0x0000000105413b5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    25  CoreFoundation                      0x00000001053f8e54 __CFRunLoopDoBlocks + 356
    26  CoreFoundation                      0x00000001053f85ee __CFRunLoopRun + 894
    27  CoreFoundation                      0x00000001053f8016 CFRunLoopRunSpecific + 406
    28  GraphicsServices                    0x0000000108d15a24 GSEventRunModal + 62
    29  UIKit                               0x00000001032fc134 UIApplicationMain + 159
    30  –¢–∞–∫—Å–∫–æ–º –ö–∞—Å—Å–∞           0x0000000100c2619f main + 111
    31  libdyld.dylib                       0x00000001061f365d start + 1
    32  ???                                 0x0000000000000005 0x0 + 5
)

Is it possible to resolve this error and make it work properly?

Moreover, in some cases, it could be useful for me to apply methods of both KIF and XCTest. So, is it possible to use these frameworks together in one test case?

0

There are 0 answers