Questions tagged [xctest]

XCTest is an Apple-provided framework which implements unit testing functions. It works with iOS 7 and all versions of OS X.

XCTest is a testing framework initially released with Xcode 5, provides a common framework for writing unit tests. XCTest supports unit testing for iOS, IPadOS, tvOS, watchOS, and macOS projects.

XCTest is part of the following SDKs:

  • Xcode 5.0 and later.

References

1962 questions
48
votes
1 answer

What's the difference between XCTAssert and XCTAssertTrue?

What's the difference between XCTAssert and XCTAssertTrue? They seem to be doing the same thing, if so why do we need both?
Boon
  • 40,656
  • 60
  • 209
  • 315
44
votes
5 answers

Unit Test fatalError in Swift

How to implement unit test for a fatalError code path in Swift? For example, I've the following swift code func divide(x: Float, by y: Float) -> Float { guard y != 0 else { fatalError("Zero division") } return x / y } I want…
mohamede1945
  • 7,092
  • 6
  • 47
  • 61
44
votes
9 answers

Xcode 5 says tests failed but shows green checkmarks

I have written a few unit tests in the new XCTest framework of Xcode 5. The tests seem to pass successfully most of the time, but I've come across a strange behaviour where if I run the tests enough times consecutively, eventually I'll get a 'test…
Shinigami
  • 2,123
  • 23
  • 40
43
votes
16 answers

Xcode 5.0.2 dyld: Library not loaded: @rpath/XCTest.framework/Versions/A/XCTest

I have problems running a project in Xcode 5.0.2 I get the following error: dyld: Library not loaded: @rpath/XCTest.framework/Versions/A/XCTest Referenced from:…
user637338
  • 2,565
  • 1
  • 25
  • 26
42
votes
3 answers

iOS UI Testing On an Isolated View

I'm trying to incorporate UI tests in my iOS project, but one thing that continues to hold me up is the fact that it seems all of the tests you write must start from the beginning of the app and work their way through. For example, if I want to test…
mike
  • 1,441
  • 2
  • 19
  • 31
42
votes
12 answers

iOS Testing: Is there a way to skip tests?

I don't want to execute certain tests if the feature is currently disabled. Is there a way to "skip" a test (and to get appropriate feedback on console)? Something like this: func testSomething() { if !isEnabled(feature: Feature) { skip("Test…
scrrr
  • 5,135
  • 7
  • 42
  • 52
42
votes
4 answers

XCTest and asynchronous testing in Xcode 6

So Apple said in the release note of Xcode 6 that we can now do asynchronous testing directly with XCTest. Anyone knows how to do it using Xcode 6 Beta 3 (Using objective-C or Swift)? I don't want the known semaphore method, but the new Apple way.…
Dimillian
  • 3,616
  • 4
  • 33
  • 53
42
votes
5 answers

XCTAssertEqual error: ("3") is not equal to ("3")

NSMutableArray *arr = [NSMutableArray array]; [arr addObject:@"1"]; [arr addObject:@"2"]; [arr addObject:@"3"]; // This statement is fine. XCTAssertTrue(arr.count == 3, @"Wrong array size."); // This assertion fails with an error: ((arr.count)…
Sergey
  • 47,222
  • 25
  • 87
  • 129
40
votes
3 answers

How to wait in a XCTest for T seconds without timeout error?

I want to delay progression of a test for T seconds, without generating a timeout. First I tried the obvious: sleep(5) XCTAssert() But that failed. Then I tried: let promise = expectation(description:…
meaning-matters
  • 21,929
  • 10
  • 82
  • 142
40
votes
2 answers

Xcode 5 Product -> Test is grayed out

My Xcode 5 Product -> Test is grayed out but I can still run my unit tests directly by clicking play from the Test Navigator. Any idea what's causing Product -> Test to gray out?
Boon
  • 40,656
  • 60
  • 209
  • 315
40
votes
2 answers

What is the purpose of XCTestCase's setUp method?

Per the comment within the default template for XCTestCase regarding setUp : Put setup code here; it will be run once, before the first test case. However, in XCTestCase.h, the comment above setUp states differently: Setup method called before the…
JRG-Developer
  • 12,454
  • 8
  • 55
  • 81
38
votes
7 answers

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

Is it possible to run individual test cases, or individual test suites, from an iOS app test target, instead of all the test cases, from a command line interface? You can run tests from command line with xcodebuild, out of the box. When you do so,…
Apophenia Overload
  • 2,485
  • 3
  • 28
  • 46
38
votes
12 answers

Error with XCTestExpectation: API violation - multiple calls made to -[XCTestExpectation fulfill]

I'm using XCTestExpectations in Xcode 6 (Beta 5) for asynchronous testing. All my asynchronous tests pass individually every time I run them. However, when I try to run my entire suite, some tests do not pass, and the app crashes. The error I get…
Mihir
  • 982
  • 1
  • 7
  • 13
36
votes
11 answers

Xcode 7 Tests don't run but reports success

I'm trying to add a test target to my project, however When I run the tests it seems like the actual tests aren't being executed, instead Xcode reports success always, but the small square which indicates if the test passed or not remains clear. I…
Emanuel
  • 1,981
  • 1
  • 20
  • 28
36
votes
7 answers

Ordering unit test using XCTest in Xcode 6

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. For example I want to run the SitchozrSDKSessionTest before running…
BoilingLime
  • 2,207
  • 3
  • 22
  • 37