When running our Robocode robots, we may find that they don’t exactly work according to our design. We can run acceptance tests, behavioral tests, and unit tests on our robots to make sure that they run to our specifications. These tests do not just provide benefit to the current robot, but future robots as well. They provide regression testing so we are able to revert to an earlier version that performed better.
Acceptance tests with JUnit provide a clear benefit to robocode testing. Normally you would have to start the Robocode GUI and run a match between two robots. Since the specification is that the robot must beat 8 robot types, having acceptance tests to make sure that the robot wins is necessary. My current robot, EasyKillBot, has passed on average 3 of the acceptance tests, where the goal is to win 10 out of 10. While creating a robot that can win against these robots each time is unlikely, these tests provide a gold standard to aim for.
The behavioral tests are where I put most of the effort in testing. I created tests which tested the robot’s accuracy and the states which would be detrimental to the robot’s functionality. The detrimental states that I tested for are hitting a wall(lose energy), disabled(a sitting Duck that can’t do anything), and robot collisions(both robots lose life). I didn’t test movement because the EasyKillBot is currently set to move in a circle and can be seen with the “eye test.”
The current state of the EasyKillRobot doesn’t have any unit tests. The reason is that the code coverage for the current robot behavior consists mostly of methods with no arguments and no return values. Eventually when I modularize the code and include methods such as the included method, public double distanceFromCircle(distanceFromCircle(Point2D myLocation, double maxRadius), I will include unit testing for the proper functionality.
I also was able to test my build within Eclipse with the instructions here. It removes one less hassle so I wouldn’t have to keep switching between Eclipse and command-line to test. One issue I ran into was that I had to set up the VM run configurations for each test.
I found great value in creating code to test robots and testing in general. In the Robocode GUI, the “eye test” only gives so much information. I also found enjoyment in creating behavioral tests for my robot. The behavioral tests make sure that the robot lives up to certain expectations that the designer chooses to impart upon it. The main benefit of the JUnit testing is that I have become a bit more proficient in JUnit, which will help in future projects I undertake.