Thursday, January 19, 2006

OK - so I grit my teeth and do a search for a bug about enabling assertions in the Eclipse bugzilla. I grit my teeth because I've done this before and it is often an exercise in frustration. The bug database is so big it hides everything like a haystack full of needles, and everybody uses obscure tribal languages in the descriptions that you hope are related to the thing you're searching for. Invariably, they're not, at least they're probably not but you're not quite sure. But then maybe that one from two searches back was really the one you wanted after all... If you try to get back to that one you can't find it because you forgot the exact keyword combination you used before and you see a bunch that look similar but not quite the same and none of them are really related to what you want so you give up.

Well, by some miracle of violated expectations, I found the exact bug I was going to enter right near the top of the query results. It had been sitting for a couple of years and no one had fixed it. It was bug #45408, titled "Enable assertions during unit tests [JUnit]", opened by Kevin Klinemeier. Here is the stack of discussion from the bug, with my offer to fix it second from the end:

Description: [reply] Opened: 2003-10-22 14:49

As I understand it, Java 1.4 assertions are disabled by default unless the vm
argument "-ea" exists. I would like very much for Eclipse to have an option to
always enable assertions while running my unit tests from the "run as... JUnit
test" menu item.

I realize that I can define a runtime configuration and specify the parameters
there, but if this were the "default", that would be very helpful.


------- Comment #1 From Dan Allen 2005-06-03 00:53 [reply] -------

Additionally, I would like to see a switch somewhere in the run dialog titled
"Enable Assertions". Having to type the -ea switch in the JVM arguments is far
too low-level for eclipse and not very user friendly. I would almost even argue
adding a "Run Java Application with Assertions" in the Run menu.


------- Comment #2 From Edward Willink 2005-06-23 13:56 [reply] -------

Surely there should be a Compiler preference?


------- Comment #3 From Andrew Scherpbier 2005-06-23 14:28 [reply] -------

(In reply to comment #2)
> Surely there should be a Compiler preference?

This is not a compiler issue so much since java 1.4 assertions are always
compiled into the class files. The issue is the (default) enabling of
assertions at runtime.


------- Comment #4 From Edward Willink 2005-10-07 09:46 [reply] -------

Indeed, not a Compiler Preference.

There should be a Workspace->Preferences->JUnit config to set -ea as a default
for all auto-generated launch configurations, and possibly for manual ones too.


------- Comment #5 From John Kaplan 2005-12-14 10:58 [reply] -------

Is anyone on fixing this one?
It bothers me enough I'm willing to work on a fix.


------- Comment #6 From Edward Willink 2005-12-14 12:05 [reply] -------

There is a slightly clumsy workaround which works fine once you've learnt it.

If you put -ea as a VM argument in a Test All launch configuration, it
works, and is inherited when you select some test(s) to redo from the
subsequent
JUnit window.

It's only when you do a Run As->JUnit Test on an IResource selection that you
lose the -ea, and get deceived into thinking everything's good till the next
Test All.

- - - - - - - - - -

This bug was assigned to Erich Gamma. You gotta figure the dude's pretty busy, so I didn't think flaming him to get on it and get his bugs fixed would be appropriate. Instead, a diplomatic e-mail might do the trick, so I wrote the following:

Fixing eclipse bugzilla #45408 (enable assertions)

Hello Erich - I am interested in submitting a fix for this bug #45408 (Enable assertions during unit tests [JUnit]).
I see it is assigned to you and didn't want to step on toes if you were actively working on it, or planning to do so in the near future.

If it's OK with you, I'd start by making sure there was a consensus for the user interaction.

My first proposal would be to have a new panel in the Window > Preferences... > Java > JUnit section that had a checkbox for "enable assertions by default for all JUnit test configurations." Then have a checkbox in each of the Run... and Debug... JUnit configuration dialog panels that says "enable assertions." That's the basics, but also it seems this check box should remain in 2-way sync with the -ea VM argument.

I'd go with the consensus if there are other opinions as to how to do it, but I'd like to start a discussion on the bug list.
Once there was a consensus I'd like to develop and submit a fix.

Hope to hear from you soon,

Thanks,
- John

- - - - - - - - - -

Erich replied:

Hi John,

Markus Keller is now taking care of the JUnit integration. I've reassigned
the bug to Markus and I agree that the discussion should continue in
bugzilla

--erich

- - - - - - - - - -

So onwards we go...

0 Comments:

Post a Comment

<< Home