Unit testing

rapodaca

New Member
Contributor
I just ran into a bunch of problems trying to set up some simple unit tests. I resolved them and you can see the result here:

https://github.com/rapodaca/Terasology/ ... yTest.java

Inventor depends on Player. Player depends on WorldRenderer. WorldRenderer depends on OpenGL stuff, and it looks like an entire world needs to be generated to just test something simple like Inventory.

So I made some changes that made Inventory testable under reasonable conditions. One change was to mock Player with Mockito:

http://code.google.com/p/mockito/

Another was to not load default items on constructing Inventory, but require Player to do it.

There are some tests in the /tests directory, but very few.

So my question - what's the plan for testing and would there be a problem with these kinds of changes getting added into the MovingBlock master branch?

This exercise has brought up other issues as well. For example, why does an Inventory even need to know about Player in the first place? Should be the other way around, no? Probably a separate issue, though.
 

Immortius

Lead Software Architect
Contributor
Architecture
GUI
I think it is fair to say that much of the existing Entity types and game logic is rough - just enough there to test that the world stuff works. I suspect much of will be re-written, either in moving towards an entity system or when adding multiplayer support.

I agree that things aren't very well structured for testing in general though - too many singletons, not enough interfaces, some questionable dependencies. The chunk tessellator performance test I wrote had to basically run the entire game in a 0x0 window to work.
 

Cervator

Org Co-Founder & Project Lead
Contributor
Design
Logistics
SpecOps
Top