An Eclipse Template for Parameterized JUnit Tests
After refusing much of any changes, especially the ugly TestDecorator fixture, after TestNG showed up, JUnit went bonkers with a spasm of matching features. Parameterized tests were in 3.8.1, but in 4.x, they were redone with annotations. The results were rather unspectacular. Mainly because you can never really remember exactly how to put one of them together.
Which makes it a perfect candidate for an eclipse template.
Developing this one turned into a nightmare. Mainly because it was the first time I needed multiple imports, and the posts I found on the internet all showed just one, didn‘t know that you had to list the types, comma-separated in a single var declaration. I was kind of amazed at the state of the documentation about the templating system in eclipse now: there is a lot of crap in there. Frankly, I kept thinking ‘ugh, heuristics is still utterly lost in development: we either don‘t document things, or whittle them down to minute detailed schematics, hardly ever achieving a fluid balance between examples and specs.‘ [Ok, that was kind of a long half-quoted thought.] I still wish the template system would allow me to define a var and then the same name but small first letter so I could get an instance without retyping.. ! Might be in there, who knows.
The real timesuck was the package statement in my template (I like to clear out the whole file with Apple-A/DEL) and no matter what I did, the package appears below the imports. Can eclipse really be this stupid a decade on? I finally relented and removed it for now.
Here is the template. I think it does make it quicker to setup a parameterized test, and relieves you of having to try to remember the non-intuitive way the plumbing is done.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)