Wednesday, March 09, 2005

Eclipse Not Finding My TestCase

I wrestled with Eclipse yesterday, regarding a JUnit TestCase. I had always just added a class derived from TestCase, implemented my test methods, and Eclipse has always just run it. I have a Run task that runs all test cases in the project, and I've never had to do anything special. Until today. (Well, sort of.)

Today, I added a new TestCase-derived class. And because I try to write (at least) one test method for each method in the tested class, I copied my actual methods over to the test class, and renamed the methods to start with 'test'. (Yes, I know I should have tested first. Sorry.) I then added an implementation, and ran it. And it passed.

Hmm. My tests usually don't run right the first time, and frequently I sabotage them to make sure they don't, so I know they're being run. I check Eclipse's run window, and sure enough, they're not being run. I go into the Run dialog, and I can't even specify the class in the single-test option.

After much wrestling and wrangling, it turns out that my flaw was in copying the methods over. Seems I forgot to take the parms out. Seems that Eclipse saw no void methods w/no parms starting w/'test', and assumed that this wasn't a TestCase. And wouldn't even show it.

Now, if it sounds like I'm a little miffed at Eclipse, I suppose I am. But what *should* Eclipse have done? Ideally, I suppose a failure could have come up, saying "cannot run anything in this TestCase". Or at least show the class in the Run-single mode, and complain when I try to save it that there aren't any methods with the required signature.

Anyway, now I know. And I'll go back to writing the test cases first. I promise. <sulk>


Post a Comment

<< Home