Eclipse and JUnit

I started building a little Java app this evenings.  First time I've done Java SE work in a long time, and it's kind of nice.  Not sure why I picked Java instead of Groovy, but whatever.  Probably the same reason people go home for the holidays.

In any case, being the good developer I am, after designing the core interfaces, I wrote some unit tests using JUnit 4.  Right click on the file in Package Explorer, hit "Run as JUnit Test" and it fires up in a fast view to show you how you did.  All very handy.  After a few tests, i figured I should build some test suites, but I really didn't want to.  I don't know about anyone else, but I always end up forgetting to register some test or another, and then I create a regression that would get caught by that test, but since it's not registered it doesn't run, and it's just bad.  So I didn't, and continued to run the tests individually.

After half an hour or so so, I had the idea to try right clicking on a package and see if I could run all the test in that package.  I was quite pleased to see that you can.  Same thing works at the source folder and project levels.  Little efficiency improvements like that make Barney a happy boy.  Of course, still have to write the suites if I want to run them from CI or the like, but this project at least will very likely never get there.

2 responses to “Eclipse and JUnit”

  1. marc esher

    barney,
    small consolation, i know, but one nice feature about the junit plugin in eclipse is that once you have your suite created (even if it's empty… it just needs to be a junit test suite), you can right click on the file and select "Recreate Test Suite".

    I'm in the same boat as you… I am pretty bad about forgetting to add tests to the suite. Recreate Test Suite helps keep me in the habit.