Testing
This week we focused on creating JUnit tests, and it was up to us to create test a six test cases that would adequately ensure the quality of our robots. Along with JUnit we used a Java code coverage tool called JaCoCo which will check to see what lines of code are executed every time you run a program. This helped a lot when testing my robot's evade() method.
Test Cases
Quality Tests
TestCakeBotAim: My bot tracks enemy movement with its gun, this is a simple test which checks that the gun adjusts its heading appropriately when the enemy or my bot moves. This is a basic black box test to ensure that the number that comes out of the method is the expected value depending on the input.TestCakeBotFiring: I implemented a method so that my bot can adjust it's power based on the distance to the enemy. This test ensures that my bot is firing weaker shots on opponents that are further away, and stronger shots when they are closer.
TestCakeBotWall: A simple test that makes sure that my both changes its heading upon hitting a wall of the robocode battlefield. The bot may not hit every wall in the test, but it is alright because as long as it can be proven to work on one wall it should apply to all others.
TestCakeBotEvade: Depending on where my bot gets hit by a bullet it will change its heading by 45° into the shot. The bot slightly favors turning right (as it will go that direction when hit from straight on). This test case checks that the bot is turning the correct direction when hit by a bullet. JaCoCo was especially helpful with this test case as I figured out that my bot would always turn right due to a logic error in my conditional statements.
Acceptance Tests
CakeBotVersusSittingDuck: A very simple test against a bot that does nothing.CakeBotVersusCrazy: Pits my bot against a bot that performs random actions.
In both of these tests JUnit will run the bots in Robocode and check if my bot will win 10/10 battles. If my bot happens to lose 1 match the test will fail.
Thoughts
This was quite a learning experience, as well as the most extensive testing I've performed on a single program. There were a few modifications I had to perform on my robot's code to make some of the actions testable! For instance my evade() and smartShot() methods had to be redesigned to return double.
On the other hand, I had some trouble designing the test that checked to make sure that the robot would change its heading when it ran into a wall. Fortunately I was able to modify some code by our professor which originally checked if a bot visited certain locations on the battlefield in a match to instead test the heading of the bot as it approaches the sides of the battlefield.
The acceptance tests were the easiest tests since there isn't really any specific code that you have to test. All that matters is that your bot wins (which isn't too hard when your bots are SittingDuck and Crazy.)
Testing for specific onEvent calls were the hardest to test. Technically you can't call any of your robot's methods outside of its run() method, so I had to manually create my own events and populate it with the appropriate parameters to test a few of the robot's methods.
Overall, it was a fun project that. My future projects will be designed with testing in mind so that I won't end up modifying many of my methods.
Here is the latest distribution file of my bot: robocode-ahg-cakebot.zip (requires Apache Ant v. 1.8.1)
No comments:
Post a Comment