35

In the "Call Hierarchy" View, it shows all methods calling a selected method. I'd like to be able to filter out everything in src/test/java so I can see what actual code is calling, instead of 100 Unit test methods.

I tried adding a name filter on Test but it didn't seem to work. I think that filters based on method name, and I'm using JUnit 4 so method names don't contian test, just an annotation, though our class names generally end in Test or TestIT. Any other ways to filter based on source folder or Class name?

I'm using Indigo with M2Eclipse to configure standard Java projects.

Thanks,

2 Answers 2

53
  1. In the Call Hierarchy view, click the white downwards arrow icon.
  2. Select "Filters...".
  3. Check "Filter Test Code".
  4. Click the refresh button (or press F5).

The test classes and methods should not be visible anymore.

The "Filter Test Code" checkbox was added in Eclipse Photon. In earlier versions, you can select the "Name filter patterns" checkbox and filter tests based on your naming convention (e.g. if the classes end with "Test" then enter *Test).

5
  • 2
    Solution by E-Riz works perfectly and is more "safe" - doesn't need naming convention.
    – Jakub
    Commented Feb 28, 2013 at 9:16
  • 1
    @Jakub But you need to add all dependencies by hand. I ended up using both answers, E-Riz's if I don't need to search in dependencies, too.
    – jan
    Commented Apr 24, 2014 at 9:08
  • If all end with "Test", you don't need * in the end.
    – Line
    Commented May 10, 2017 at 13:55
  • In Eclipse Photon, the Filters dialog now includes a "Filter Test Code" option, so no naming conventions or working sets are required.
    – Toper
    Commented Oct 10, 2018 at 14:40
  • I am no longer using Eclipse. Feel free to edit the answer @Toper with the new steps.
    – arin
    Commented Oct 10, 2018 at 16:41
14

You can define a Working Set that only includes Java source but excludes your unit tests, then select Search Scope > Working Set... in the Call Hierarchy view menu.

Search the help for more details on Working Sets.

4
  • I wish there was a better solution, but this one does seem to work.
    – RLZaleski
    Commented Feb 24, 2012 at 0:31
  • 2
    This approach is not useful for also searching in dependencies of production code, as they need to be selected all individually, i.e. it is not possible to add only src/main/java. Even if one selects all by hand the working set has to be changed each time dependencies change.
    – jan
    Commented Apr 24, 2014 at 9:04
  • @jan so it is and it isn't. It isn't because you can't just have a quick click to do it. It is because life finds a way. You can find your working set saved off in <workspace>\.metadata\.plugins\org.eclipse.ui.workbench\workingsets.xml and edit it in a programmatic way and restart your eclipse. I wrote a python script to do it for me. Sure it's not as convenient as a point and click, but you're using eclipse because you're a developer so this shouldn't be too invasive. Commented Apr 17, 2018 at 19:16
  • @searchengine27 So it is and it isn't. I'm a developer, but want to be productive. That's why I won't accept this solution or describe it as not "too invasive". :)
    – jan
    Commented Apr 18, 2018 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.