How can you create the following structure:
CoreDataTests : XCTestCase
Entity1CoreDataTests : CoreDataTests
Entity2CoreDataTests : CoreDataTests
Explanation: I would like to write some tests related to core data (check), but I want to split them up into different test case classes, so in one test case class I would have tests related to the User
entity, in another, the tests related to Comment
entity. The catch here is that I'd like the two test case classes to share the setUp
and tearDown
methods implemented in CoreDataTests and just call them with super
instead of having to copy-paste it around.
But since CoreDataTests
is a test case class, it doesn't have a header file, so the EntityTest
classes complain that they don't have a base class specified.
You can just create a subclass of XCTestCase as you would a normal class, with .h and .m files.
So just File Menu > New File > New Cocoa Class with XCTestCase as the super class.
You can then create new tests using that as the super class, however, you'll still need to import the superclass .h file as it's not added automatically.
I did this for exactly the same reasons, testing core data and having common methods to setup up the context.
One annoying thing though, it still shows up in the tests GUI, just with no tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With