Integrating GoogleTest with Xcode 4

I been thinking and reading about Unit Testing for a long while, but never dared to actually implement it in any of my projects (both in work and hobby projects) for various reasons the most obvious one being ‘laziness’.

But all of a sudden I got enlightened yesterday and been sincerely reading about UnitTest++, googletest and some other testing frameworks and decided to go with googletest for obvious reasons.

I downloaded the framework but found that the official xcode integration guide is out of date now and I couldnt easily find any other guides to integrate it with xcode 4 (mine is 4.2). So here I am writing one….

Building the gtest framework

  • Download the framework.
  • Extract the zip.
  • Open the xcode project @ gtest-1.6.0/xcode/gtest.xcodeproj
  • Select gtest-framework Scheme and build the project.
  • If you get the errorThe run destination My Mac 64-bit is not valid for Running the scheme ‘gtest-framework’. The scheme ‘gtest-framework’ contains no buildables that can be built for the SDKs supported by the run destination My Mac 64-bit. Make sure your targets all specify SDKs that are supported by this version of Xcode“, try setting the following for both `Project` and `gtest-framework` Target:
    • `Base SDK` to any proper available SDK.
    • `Compiler for C/C++/Objective-C` to any proper compiler. LLVM GCC worked for me.

scheme selection for gtest-framework

  • On successfull compilation, right click on gtest.framework in Products folder in Navigator and select ‘Show in Finder’

build products for gtest-framework


  • Copy the gtest.framework folder to a common location (mine is /Users/saiy2k/projects/gtest-1.6.0/products)

Integrating with Real Project

  • Open the project in which testing capabilities need to be added.
  • Click on the project name in Navigator.
  • Create new target by clicking ‘Add Target’. (pic)
  • select Mac OS X –> Application –> Command Line Tool
  • Enter Product Name and other fields and click finish.
  • Selecting the newly created Target and goto Build Phases tab.
  • Add gtest.framework in our common location to ‘Link Binary with Libraries’

adding new target and adding gtest framework to it

Writing Test Case and Testing

In the Project Navigator, you should be having a new folder in the name given to the Target project. Under that project create a header file ‘TestCase1.h’ with the following contents:

TEST(SampleTest, Zero) {
    EXPECT_EQ(0, 0);

TEST(SampleTest, Positive) {
    EXPECT_EQ(1, 1);
    EXPECT_EQ(6, 3*2);
    EXPECT_EQ(20, 10*2);

TEST(SampleTest, Negative) {
    EXPECT_EQ(-1, -1);
    EXPECT_EQ(-2, -2);
    EXPECT_EQ(-3, -3);

Now select the scheme for New Test Target and run it and check the log for output of the test run. For writing actual test cases, refer the googletest wiki.

Interesting HTML5 Games around

I have been playing a few HTML5 games and reviewing a lot of them lately and found some amazing games, which unleashes the true potential of HTML5, showcasing the ultimate possibilities that could be done with HTML5. I just want to share some of them here and will update the post whenever I find something which belongs to this list.


1. Entanglement

Entanglement is a strategic puzzle game, where you gain points by forming and connecting   lines across hexagonal tiles maze. The goal is to make longest line without hitting the edges  and the center tile. Play Link

Entanglement ScreenShot

Screenshot of the Entanglement HTML5 Game


2. HTML5 Command and Conquer

Pakka clone of the classic Command and Conquer in HTML5 including several single player missions and multiplayer feature, developed single handedly by Aditya Ravi Shankar. Though its meant to be a proof of concept, its very good enough to be a playable game. Play Link

Command and Conquer Screenshot

Screenshot of HTML5 Command and Conquer by Aditya Ravi Shankar


3. Score Rush

Score Rush is a high action paced shoot em up game with bosses spraying bullets throughout the screen. Its highly addictive with 62M being my top score. Play Link

Score Rush Screenshot

Screenshot of the highly addictive HTML5 shoot em up game Score Rush


4. Subbania

I only played the demo version of this game. But I am highly excited about it considering the gameplay hours, levels it has. And again it is developed by a single developer fiblye. The developer’s blog post on the enormous amount of effort / frustrations with `work in progress` browser implementations and things he went through in developing the game is inspirational. Play Link

Subbania Screenshot

Screenshot of HTML5 game Subbania

HTML5 Rocks !!!