Unit Testing with Panda3D

Unit Testing with Panda3D


Code, Python, Panda3D

by Maria on 28 Jan 2014 - 01:40  

I've been playing around quite a bit with Panda3D lately. Panda3D is a game engine originally created by the Disney Corp.; it's a framework for 3D rendering and game development for Python and C++ programs. When I was first learning Panda3D, it was not obvious to me how to do unit testing, and I didn't see any documentation about it, so I thought I would share what I have learned. I think there are a few keys, which I will go over briefly, and then share the code.

1. Don't render to screen, but don't use window-type 'none' either. The one bit of advice I could find about unit testing with Panda3D, suggested using window-type none, but if you do this your camera node becomes noneType, so you will probably have to make changes to your code. Instead use window-type offscreen.

2. Use a setUpClass to instantiate your game. Panda3d has a lot of overhead that you don't want to reload every time you run a test.

3. Have a setUp method to re-configure your game to its starting state. Reload any configuration files here, and move players and objects to their starting positions. This way you you are always starting in the same state without having to re-instantiate your game. This does mean that you should separate setting up the game scaffolding from the initial configuration in your game file, but this is a good idea anyway.

4. The only real change you should need to make to your code is including an if __name__ == "__main__": conditional at the end. This will allow you to instantiate the game and start the task manager running automatically if you start the game from the command line, but won't if you import the class as a module.

5. You can step the task manager directly from the test code, allowing you to run the game for just as long or short as you need to, in order to test the logic for that particular test.

So that I don't have to worry about updating the website if I change the code, I'll point you directly to my GitHub repository for the code. Happy testing!


Unit Testing with Panda3D ~ Comments: 0

Add Comment