Reputation: 6440
I have my own little cross-platform C++ unit testing framework where unit tests look like this:
#include "Test.h"
DEFINE_TEST(myTest) {
AssertEqual(2+2, 4);
}
and are in .cpp files.
(Seems similar to the way Catch does it, among others I'm sure)
I'd like to integrate this with Xcode, so I can run my tests using Xcode's Run Tests command and utilize other tools which depend on unit tests being run that way. Ideally, I'd like each of my test cases to be a XCTest test case (though I'm fine with manually setting that up for each test) and I'd like my assertions (AssertEqual) to behave like XCTest's (XCTAssert).
Is this possible? If so, how would I do it?
(Note: not switching to just using XCtest because I'd like my tests to work on Windows as well)
Upvotes: 3
Views: 902
Reputation: 36143
Integrating with Xcode basically means ensuring:
-[XCTestCase recordFailure:withDescription:inFile:atLine:expected:]
to the currently executing test case class instance.Xcode will then populate the Test Navigator with all the runtime-discovered tests, organized under their test case class, after the first test run.
You might be able to do a large chunk of the work with macros to let the preprocessor build your test case class/es and methods at compile-time. Otherwise, you'd need to go through and hook everything up at runtime, before the test runner polls the runtime to discover all the XCTestCase
subclasses and their test methods.
Upvotes: 1