Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple XCTest for UITest is failing all the time?

I start a new project from File -> New -> project

I add a button to ViewController.

I open UITest folder which created by xcode by default. Run the test code.

It fails:

2016-03-16 12:57:09.191 XCTRunner[3511:150419] Continuing to run tests in the background with task ID 1
    t =    10.18s         Assertion Failure: UI Testing Failure - Failed to background test runner.
/Users/Bernard/Desktop/ExampleTestApplication/ExampleTestApplicationUITests/test2.m:27: error: -[test2 testExample] : UI Testing Failure - Failed to background test runner.
2016-03-16 12:57:12.789 XCTRunner[3511:150419] *** Terminating app due to uncaught exception '_XCTestCaseInterruptionException', reason: 'Interrupting test'

Now I add a break point as follow:

enter image description here

Now test is successful! Anyone can explain the reason?

like image 470
Bernard Avatar asked Mar 16 '16 02:03

Bernard


People also ask

What is the difference between XCTest and XCUITest?

XCTest / XCUITest is pure iOS and cannot help the team that needs to test both iOS and Android devices. XCUITest was built for the iOS and Xcode Developer in mind and focuses less on the QA Automation Engineer.

What is XCTest used for?

Overview. Use the XCTest framework to write unit tests for your Xcode projects that integrate seamlessly with Xcode's testing workflow. Tests assert that certain conditions are satisfied during code execution, and record test failures (with optional messages) if those conditions aren't satisfied.

What is XCTest?

XCTest: XCTest is a testing framework that allows you to create and run UI tests, unit tests, and performance tests for your Xcode projects in Swift and Objective-C languages. It is pre-built with Xcode.


1 Answers

I was also facing same issues and none of the available solutions worked for me. Issue was not letting app to attach to the simulator itself. I checked the log and saw that i did a mistake in code while locating the element. for Predicate instead of BEGINSWITH i wrote STARTSWITH and this was stopping the app to get attached. So check your logs in the test report to get the issue.

like image 193
pawan singh Avatar answered Oct 10 '22 19:10

pawan singh