Sami Dalouche
Sami Dalouche

Reputation: 644

How to run tests sequentially in Xcode 6 beta3

From what I can see, it looks like Xcode runs tests from a given TestCase sequentially, but from different TestCases in parallel.

Is it possible to configure a project/target so that all the tests run sequentially ? For instance, this would be useful to run various integration tests that have side effects affecting the other tests. (e.g. access to same database tables)

EDIT: to clear out some confusion: I am not talking about forcing a specific sequence of tests, just about making sure that the tests do not interfere with each other.

Thanks

Upvotes: 16

Views: 3430

Answers (2)

Aaron Kapilivsky
Aaron Kapilivsky

Reputation: 11

If you need your objects to have a consistent starting state for tests, I would recommend adding calls to the setUp method of your test classes. setUp called before each of the tests in a test class.

If you need your suite to run in a certain order, it sounds like you don't have unit tests and are running integration tests. You can try to use setUp to initialize your lower-level objects. If you are only interested in the behavior of a higher-level class, try mocks. The OCMock framework is available for Objective-C.

Upvotes: 1

triiiiista
triiiiista

Reputation: 378

Not sure if this solves your problem, but could you manage to put the tests into a serial queue? It allows you to run them concurrently yet to wait for the barriers to be cleared.

func dispatch_barrier_async(_ queue: dispatch_queue_t,
                      _ block: dispatch_block_t)

https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/#//apple_ref/c/func/dispatch_barrier_async

Alternatively, you can setup multiple contexts and merge them afterwards.

Upvotes: 0

Related Questions