<-- home

[Updated] Subclassing XCTestCase Trick

###Update:###

As XCode 6.3 this no longer an issue, now is possible to name XCTestCase subclasses with any prefix without losing the ability to run tests from the test method signature. Let’s try:

Example

PS. As we initially mentioned, subclassing XCTestCase is not an elegant solution (I would prefer Class Categories ), but if this is your last resort, be my guest.


As the old saying goes, “Prefer composition over inheritance”, but in some cases subclassing is the way to go, like when you can extract some common code for all your tests cases classes in an overridden setup method.

But If you subclass XCTestCase with your own implementation, subsequent classes will lose the ability to run the test directly from the testing method.

How to fix it?

Make your subclasses name to start with ‘XC’ prefix.

i.e.


@interface XCRBTTestCase : XCTestCase{...}

This will tell XCode to enable running from method again.