Search code examples
c++xcodeunit-testingcocos2d-x

Unit Testing with Cocos2d-x and Xcode


Hey I am currently working on my first app using cocos2d-X. I'd like to test it using a unit testing framework. I tried to use googletest but didn't get very far because it kept throwing errors. Has anyone found a good tutorial or knows how this can be achieved? I don't mind using a different framework than googletest. Any input is highly appreciated.


Solution

  • I finally got it to work with Xcode's built in Testing Framework:

    To set up the environment add “Cococa Touch Unit Testing Bundle” as a new Target to your project. Make sure the cocos-2dx’s library files also target your Test Files now. Simply browse to your project folder, re-add them and select both projects as their target. Next, link the required binaries with your Libraries under “Build Phases”.

    It should include: • CoreGraphics • AV Foundation • AudioToolbox • OpenAL • OpenGLES • CoreData • Libsqlite3 • QuartzCore • SenTestingKit • UIKitFramework • Libcurl (This might not appear automatically when you click ‘+’, simply search in project folder and add it manually)

    Under “Build Settings” change the following:

    • Build Active Architecture Only: YES • iOS Deployment Target : iOS 5.0 • Strip Style: All Symbols • Skip Install: NO • Other linker Flags: -lxml2 –lz • Force Package Info Generation: YES • Add (don’t delete any existing paths) to Framework Search Path: "$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks" • “Symbols Hidden by Default”: Debug: NO / Release : YES • C++ Language Dialect: Compiler Default • C++ Standard Library: Compiler Default • Objective-C ARC: NO • Empty Loop Bodies: NO • Uninitialized Variables: NO • Duplicate Method Definition: NO

    Now import the cocos2d-X header file to your Unit Test file. The Unit Test’s .m File Type must be changed to Objective-C++ Source.
    You should now be able to test your code.