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:
- Not Using Precompiled Headers.
- Included to AdditionalDependencies all *.obj files from game project, begining from AppDelegate.
- Included to Additional Library Directories path to “…\proj.win32\Debug.win32”, “…\cocos2d\cocos”
- Included to test.cpp all files’ headers, like “#include “…/Classes/AppDelegate.h””
- 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:
- Create new empty cocos2d-x game “unit_test_project”. Run and check that everything works.
- 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);
}
- Create library for your game code “my_game_library”
- 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!