views:

243

answers:

1

I've spent a few hours searching for this, and can't find it, so I'm asking. Why here?

How can I customize Eclipse so that when I create a new JUnit test class or method, it includes different items? For other source, I'd just go into Window->Preferences, and change the templates.

But for JUnit, that doesn't seem to be possible.

I've recently installed MoreUnit, and that doesn't seem to help either.

Anyone have a pointer?

+8  A: 

It does not seem to be directly available.

The idea has been raised to save a file (like a JUnit empty file) as a template, to reuse it at future (JUnit for instance) creation time.
This is bug 37440... and it is not very popular (since 2003!).

The closest would be

Window > Preferences > Java > Editor - Templates and look under "test method (JUnit4)"

However, as mentioned in this thread:

but that will not affect the auto-generated JUnit test method stub templates.
In other words in the New JUnit Test Case dialog, one can select the methods of the class under test and test methods stubs are auto-generated.

To modify the template that creates these JUnit test method stubs... seems not possible at the moment.

Bug 71783 is somewhat related to this issue, regarding the comment templates of those methods.

Note: the generation of the JUnit class itself seems entirely hard-coded in the class

org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne


Speaking of template, you also needed to to provide VM arguments to all JUnit tests you run, manually copying them for every new configuration.
Bug 37862 has been set to address that and allow to create a Installed JRE for use with a JUnit testing, configuring it with the correct set of VM arguments.

VonC
+1 very thorough
Rich Seller
Excellent, though disappointing, answer. Thanks.
CPerkins