JUnit testing

After many years of "I've been meaning to try this!" but never actually having time to do so, I finally incorporated my first JUnit test into a codebase.

In Eclipse, I right-clicked on the package containing the class I wished to write tests, for, then I chose New --> Other --> JUnit Test Case, click Next, then create a class name (ex. MyClassTest) then finish.

Next, write your test methods.

Next, right click on the new class in the Project Explorer, then choose Debug As -> JUnit Test.  (I originally goofed up here because I picked Run As --> JUnit Test.  But when I did that, the variable inspection features didn't work!)

Next, the perspective will change to Debug, then you can click the items in the Variable column to view the contents, set break points, etc..

This is my favourite part about my job!  Too bad it's so rare I get to do this, hahah!

Eclipse / JUnit links
  • http://courses.cs.washington.edu/courses/cse143/11wi/eclipse-tutorial/junit.shtml 

No comments:

Post a Comment

Translate