I'm playing around with a small game project and as I'm not very experienced in TDD I'd love to get some expert opinions on a couple of things.
First of all, I realized early on that TDD did not seem ideal for game development. It seems that opinions vary pretty wildly on the subject. My initial uneducated opinion was that TDD seemed as though it would work very well for all the game logic. I thought to myself that anything that would deal with video output and sound would be abstracted into classes that would be tested visually.
Things started off well. The goal was to create a 2d space flight game (asteroids for those that care). I created a series of unit tests for the Ship class. Things like initialization, rotation, can easily be tested in a series such as: GetRotation(), TurnRotateRightOn(), Update(1), GetRotation(), Expect_NE(rotation1, rotation2). Then I hit the first problem.
My understanding of TDD is that you should write the test how you think you should use the class. I want the ship to be able to move so I wrote a class that basically said. GetCoordinates(), ThrustOn(), Update(1), GetCoordinates(). That was fine to make sure the ship moved somewhere. However, I quickly realized I had to make sure the ship was moving in the correct direction and at the correct speed. What followed was a 75 line unit test where I basically had to initialize the rotation, check the coordinates, initialize thrust, update the ship, get the new coordinates, check the new rotation. What's more, I can see no need to ever get the ship's velocity in the game (just the coordinates, the ship should update itself). Because of this I had no direct way of getting the velocity. So the test basically had to recalculate what the velocity should've been just so I could make sure it matched up with what coordinates I was getting after the update. All in all this was very messy, and very time consuming, but worked. The test failed, made the test pass, etc.
This was fine until later when I realized I wanted to refactor the update code of the ship into an abstract "Actor" class. I realized that while every subclass of Actor would need to be able to correctly calculate a new position, not every subclass would necessarily update their velocity the same way (some collide, some don't, some have static velocities). Now, I'm basically faced with the prospect of duplicating and altering that huge and massive test code and I can't help but think there should be a better way.
Does anyone have any experience in dealing with unit testing this sort of complex black box type of workings? It seems like I'm basically having to write the exact same physics code in the test just so I know what the result is supposed to be. It seems self defeating really, and I'm sure I'm missing the point of all this somewhere along the way. I'd greatly appreciate any help or advice that anyone could offer.