Wednesday, October 7, 2009

Improved Junit testing With Help From Emma

So last week, we were introduced to Ant and Ivy which are great Quality Assurance tools. This week we go even further into QA by writing our own test cases and testing them with Junit. Why do test case, you asked? well, so far with Ant and Ivy, we're checked to see if our code is within a certain coding standard, that it'll compile with no error, and a simple test case to see if it'll beat SittingDuck. But we haven't test it to see if it does what its suppose to do. That's where you'll need the additional test case.

There were three types of test case that we have to write and test our robots with. They are acceptance (if the robot can consistently beat it's target), behavioral (verify that the robot satisfies a component of the strategy), and unit (verify that individual methods calculate the correct value) tests. The acceptance test were quite easy since our professor gave us an example of it which was tested against SittingDuck. By making a modification to the code changing the target robot name, I was able to create 2 new acceptance test case for my robot (SideStep) to go against Crazy and Walls. Both test passed via Eclipse and Ant, which was great considering that I had the hardest time getting Junit to work in Eclipse. ( After many fail attempts, I finally deleted Eclipse and reinstalled it and somehow Junit is working now with the same configuration that I used with the old one).

For the behavioral test, I created one that would test to see if my robot would fire only if the target is within 400 pixels. First off, writing test code was a lot harder than writing the actual code. I couldn't figure out how to call methods from other classes that I used in the actual code. After writing the test code by trail and error, it was able to pass the Junit test. Junit is still very new to me and I will probably need more time to look into it. But due to time constraints from my other classes (projects and exams) this week, I didn't have enough time into reading up on it, which I'll probably do over the remainder of this week.

Even with the help of Emma, I'm only about 50% sure that I'm testing the right thing. Emma is a great tool which outputs a html file that shows which line in the code it is testing and shows if the line fail or pass the test. I will continue this assignment through the rest of this week and will update this post with new test cases and discoveries.

Here is the code for my robot including its test cases.

0 comments:

Post a Comment