Skip to content

codedragon/panda3d_unittest_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

I created this example to show how it is possible to unittest in Panda3d. It is a pretty silly example, hence the name, but I think it gives an idea about how to go about testing. First, the 'game' is a super simple game in which we have a smiley and a frowney. The player moves smiley to run into the frowney, at which point the frowney disappears. That's it. 

Testing. Starting the Panda3d game engine has a lot of overhead, so we don't actually want to do this for every test. We create a setUpClass that runs once for our suite, and here is where we instantiate our class. This is also where we tell Panda3d that we don't actually want to do any on-screen graphics. So, given that we are not going to be instantiating our game for each test, and tests run in random order, we want our tests to all start in the same configuration. So, in the setUp method, you should include any re-loading of configurations you may need to do, and any other methods that get your game into the same state it was at the beginning. It is not unheard of to give a player the ability to restart a game in the middle of it, and you probably don't want to restart the engine when a player wants to restart, so this doesn't seem a bad idea anyway. In this example, I just set smiley and frowney to their original positions in my setUp method.

The rest of the test file is just various tests to give an idea about how to set up unittests in Panda3d. I have tried to include comments in both files that will help someone just beginning in Panda3d as well. If you have questions about collisions, I highly recommend astelix's tutorial, http://www.panda3d.org/forums/viewtopic.php?t=7918.

In order to unit test, the only thing you may have to do differently in your game code itself from what you might currently be doing, is to include the if __name__ == "__main__": conditional at the end. This means that if you start the game like you normally would, for example ppython silly.py from the command line, then it will run normally, but if you import it as a module, the game will not be instantiated and will not run, which is what we want for testing.

Hope someone finds this useful!

About

Example of a super simple silly game that demonstrates unit-testing with Panda3D

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages