Google Tests && Visual Studio vs Cocos2d-x

Hi! My first post here)
Trying to implement Googletests for my game in Cococs2d-x 3v using VS 2019 Community.

My steps in test project:

  1. Not Using Precompiled Headers.
  2. Included to AdditionalDependencies all *.obj files from game project, begining from AppDelegate.
  3. Included to Additional Library Directories path to “…\proj.win32\Debug.win32”, “…\cocos2d\cocos”
  4. Included to test.cpp all files’ headers, like “#include “…/Classes/AppDelegate.h””
  5. Inside test.cpp created Test Fixtures with “AppDelegate app;”

Getting “…\Classes\AppDelegate.h(28,10): fatal error C1083: Cannot open include file: ‘cocos2d.h’: No such file or directory”

Can anybody mentor me in tests for Cocos in VS?

Hi,

That’s what I did:

  1. Create new empty cocos2d-x game “unit_test_project”. Run and check that everything works.
  2. Setup unit test environment for “unit_test_project”
    I use https://github.com/catchorg/Catch2 - header only, easy to start. You include 1 header and it works on all platforms win/mac/ios/android

In AppDelegate::applicationDidFinishLaunching() instead of

director->runWithScene(scene);

write

int result = Catch::Session().run( argc, argv );
if (result != 0)
{
   exit(1);
}
exit(0);

Run and check that everything works.
3. Write simple test. Run and check that everything works.

TEST_CASE()
{
    CHECK(true == true);
    CHECK(true == false);
}
  1. Create library for your game code “my_game_library”
  2. Link “my_game_library” to “unit_test_project” and “game_project”
1 Like

Thanks mate! I know about Catch2, though i’m more familiar with GTests. If i can’t break through GTest i’ll try your solution.Thanks a lot!