Wednesday, October 7, 2009

Testing, testing, 123

Writing JUnit tests for a robocode robot make it very easy to test to see if your robot is doing what you're expecting it to do. Also, it makes it extremely simple to check that nothing is lost while you are making changes in efforts to improve functionality. My Runner robot has an admittedly very simple strategy so there isnt much to test.

The easiest tests to create were the acceptance tests, which only checked to see whether or not my robot won a set amount of rounds against another robot. The harder ones where to check whether or not my function to keep my robot headed in a somewhat diagonal heading worked or not. Testing to see if my firing power based on distance was working correctly wasn't too hard. I wasn't able to test much more of my robot's other strategy so i used more than 2 acceptance tests.

I think it tests most of what my robot does. The only thing that isn't tested is whether or not my robot turns 90 degrees when it hits a wall. I wasn't able to figure out a way to check to see if its behavior was correct.

The results of Emma are as follows:

Emma Coverage summary
class: 90% (9/10)
method: 84% (42/50)
block: 74% (390/530)
line: 74% (100.4/135)

I have changed my robot's code to make it easier to write JUnit tests. I could definitely add more to test though.

Download the latest distribution here

No comments: