Hide unit tests from Call Hierarchy
Asked Answered
T

2

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,

Tuck answered 17/2, 2012 at 0:47 Comment(0)
F
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).

Fuzee answered 22/1, 2013 at 19:29 Comment(5)
Solution by E-Riz works perfectly and is more "safe" - doesn't need naming convention.Avie
@Avie 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.Hydrogenize
If all end with "Test", you don't need * in the end.Ternate
In Eclipse Photon, the Filters dialog now includes a "Filter Test Code" option, so no naming conventions or working sets are required.Fender
I am no longer using Eclipse. Feel free to edit the answer @Fender with the new steps.Fuzee
B
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.

Bidle answered 17/2, 2012 at 2:43 Comment(4)
I wish there was a better solution, but this one does seem to work.Tuck
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.Hydrogenize
@Hydrogenize 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.Nostology
@Nostology 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". :)Hydrogenize

© 2022 - 2024 — McMap. All rights reserved.