Showing posts with label gamedev. Show all posts
Showing posts with label gamedev. Show all posts

2015-02-25

cocos2d-x: Adding Unit Test Framework "SimpleTDD"

Introduction: 

SimpleTDD is a simple unit test framework that help you to develop tests to examine the behaviour of your codes;

Storyboard about SimpleTDD



Setup Overview

This is the steps to install SimpleTDD in your project:

1. Download SimpleTDD 
2. Run the setup script 
3. Set Macro for Debug version
4. Add Test Button
5. Create Unit Tests

Required software for SimpleTDD is just python, which should be installed when Xcode is installing;


Download SimpleTDD

Simplify clone the SimpleTDD project from the Github
https://github.com/tklee1975/SimpleTDD-cocos2dx


Run the setup script

Setup script is python script that help you to copy Library classes and script to your project;



After setup script is run, add the files to your project build; 
For XCode (iOS): 

  • File -> Add Files to "your project"
  • Select "UnitTest" and "SimpleTDD" folders
For Android: Add them in the Android.mk 


Set Macro for Debug version

SimpleTDD need you to set Macro "ENABLE_TDD" to open the route to the Test Main Menu so that It won't affect the release build;

For XCode(iOS):

  • Open "Build Setting"
  • Search for "Macro"
  • Modify "Preprocessor Macros" values 
  • Add "ENABLE_TDD" 
For Android: Define "-DENABLE_TDD" at "LOCAL_CPPFLAGS"  in Android.mk

Add Test Button

To enter the Test Main, you need add a button at your main scene;

This are the codes:
// At the header 
#include "TDDHelper.h" 

// Inside the Scene or Layer setup method
TDDHelper::addTestButton(this, Vec2(100, 80));


Create Unit Tests

These are the steps to create unit tests that help you to test individual code; You are going to do these steps many many times; It will be fine because it is not hard to do;

Create the TestSuite Class

  • Run the createTest.sh to create the TestSuite Class
    • run "./script/createTest.sh Example1" 
    • It will generate source code "Example1Test.h" & "Example1Test.cpp" in Classes/UnitTest Folder
  • Add Test Class to project 
    • For Xcode, use Add files to project
    • For Android, include these files in Android.mk
  • Edit "MyTDDCase.h"
    • MyTDDCase.h is the header file to control which Unit Test will be shown in the Test Menu
    • First, include the new Test Class using "#include Example1Test.h"
    • Second, add "TEST(Example1Test)" in the TDD_CASES block
  • When it is done, the test suite "Example1" will be shown
Create a test in the TestSuite Class


  • By default, there is test method called "subTest" in the TestSuite class; it will simply print something to the console;
  • To add a new test (e.g: testSpriteRotate), just follow the way "subTest" do;
    • Define the method in .h & .cpp;  example: void Example1Test::testSpriteRotate(Ref *sender);
    • Add the method in "setSubTest" method: example: SUBTEST(Example1Test::testSpriteRotate)
    • Do the unit test code inside testSpriteRotate method
    • Test & Run!!!

SimpleTDD Demo

A simple demo of SimpleTDD is located at github:
https://github.com/tklee1975/SimpleTDD-ccx3-demo

2013-08-29

Key Tasks of cocos2d-x development


Setup Development Environment

  • Make the iOS binary (.ipa), run on Simulator and Device
  • Make the Android binary (.apk), run on Device

Seek and Read References

  • Reference of Cocos2d-x
  • Reference of C++
  • Reference of POCO library

Create Testing Code

  • Create UnitTest for Logic (text mode stuff), suggest to use UnitTest++
  • Create UnitTest for GUI or Graphics stuff

Create Architecture / Utility / General Code

  • Clarify how MVC architecture work
  • Create Data Class
  • Create a singleton class
  • Make and understand Useful MACROs

Manage GUI, Graphics and Scene 

  • About GUI 
    • Custom View
    • Popup View
    • Fullscreen View
    • TableView
    • Scrollable View
    • Using Cocos builder to create the views
    • Gallery View
    • Loading View
  • About Graphics
    • Render Sprites
    • Render Maps
    • Render something you want to
    • Controlling the zoom and location of the Camera
  • About Scene
    • Add a new scene
    • Switch between scenes

Network Stuff

  • Connect using Socket or HTTP
  • Adding Network Protocol
    • Create Requests
    • Handle Response
    • Handle Network errors
  • Testing the network protocol

Debugging and Profiling

  • Check the potential problem
  • Check memory leak
  • Check the performance using profiler
  • Locate where and when will crash the app

Deployment

  • Create different kinds of build using Makefile/build.xml/.… 
  •  Publish the app (ipa or apk) using TestFlight