Developers Manual > Cocos2d-x > How To > User Contributed Tutorials > User Tutorial-Unit Tests in Cocos2d-x

Unit Tests in Cocos2d-x

Contributed By: rafaelpierri

Solving Dependencies

Make sure you have cocos console and wget installed, then:

    cocos new MyGame -l cpp
    cd MyGame
    wget https://raw.githubusercontent.com/rafaelpierri/gtest-and-cocos2d-x-on-a-blender/master/gtestOnCocos2d.sh
    ./gtestOnCocos2d.sh

Time to Code!

Based on the examples provided at Classes/project1.cpp, Classes/project1.cpp and tests/test_project1.cpp you can write your own Unit Tests.

If you create new files under Classes/ or Tests/ make sure to edit CMakeLists.txt accordingly. Take a look at the "#NEW STUFF" comments along CMakeLists.txt, they will give a tip on where you should add or modify the file names.

Testing

Choose your perferred build directory:

    mkdir linux-build
    cd linux-build

Run cmake including the Unit Test option:

    cmake -Dtest=ON ..

Now build'n'run:

    make
    make test

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.