views:

205

answers:

4

I've been searching high and low for an Eclipse feature that lets you right-click on a main source class and find the corresponding JUnit class(es), without me having to navigate through the test classes of my project. I am using Mylyn which helps reduce the clutter but it would be much easier if there was a feature that performs a find automagically.

I am following the Maven standard directory layout (/src/main/java, /src/test/java, etc.). And all of my test classes are named *Test. I'd imagine this can be feasibly implemented and probably already exists.

Is there a function or plugin in Eclipse that finds the corresponding JUnit test classes for a given main class?

A: 

As a partial answer to your question, there is no requirement that tests have a one to one correspondence with main classes, or any standard naming convention (even with maven). What you would want is a plugin that (for example based on a regex) matches source classNames to dest ClassNames, and then loads that. Such a plugin would allow you to do what you want (and also for other uses not related to junit), but I'm not aware of one.

Paul de Vrieze
+1  A: 

This plugin claims to be able to do this, as well as other stuff.

An useful feature of this plugin is the ability to jump between similar class, e.g FooDAO to FooService, FooService to FooAction, etc. To use this feature, one needs to configure this first. To configure, please go to Windows -> Preferences ->Fast Code Preferences -> Mapping Btween Similar Classes. This is very similar to the configuration for create similar classes.

soru
+3  A: 

The moreUnit plugin probably works for you.

Capabilities (from its site):

  • Decorate classes which have a testcase.
  • Mark methods in the editor which are under test.
  • Jump to a testcase/testmethod in the editor via the menu or a shortcut.
  • Rename classes/methods and moreUnit will rename the corresponding testcode too.
  • Move classes and moreUnit will move the corresponding tests.
  • Generate a testmethod stub for the method under cursor-position in the editor via the menu or a shortcut.
Csaba_H
This is exactly what I needed. Thanks!
0sumgain
+1 looks very interesting
Rich Seller
A: 

Infinitest plugin runs your JUnits for those classes that you're changing, as you're changing them. There is no need to right-click on the updated class to find the relevant JUnit class, and then to run it - it will get run automatically. Test errors (if any) will show up the same way as Eclipse shows syntax errors.

jprusakova