How to find Junit tests that are using a given Java method directly or indirectly
Asked Answered
E

2

6

Assume there are Java project and Junit project in an Eclipse workspace. And All the unit tests are located in the Junit project and dependent on the application Java project. When making changes to a Java method, I need to find the unit tests that are using the method directly or indirectly, so that I can run the corresponding tests locally in my PC before checking into source control. I don't want to run the entire junit project since it takes time.

I could use Eclipse call hierarchy to expand caller methods one by one until I find a test method. But for a project including more than 1 million lines of source code, digging down the call hierarchy takes time too.

The search scope within call hierarchy view doesn't seem help much.

Appreciate any help.

Epicarp answered 11/3, 2010 at 17:5 Comment(0)
L
2

Use a test coverage tool. See my answer:

How do I find all the unit tests that may directly or indirectly call a given method? (.net)

Leigh answered 25/3, 2011 at 15:52 Comment(0)
B
1

Why not right click on the changed method and select "References->Workspace (or Working Set if configured properly)".

This should give you a list of methods invoking the one you just changed. The search results can be organized by package or project. Select project organization and expand the JUnit project and what you are looking for will likely be the only thing there.

Bailiff answered 12/3, 2010 at 11:9 Comment(1)
If C is called by B, which is called by A, e.g. illustrated by C-B-A, and assuming A is the test method. When searching for references of C, it only shows B. Of course, we could again search for B's references, but it's better to use "call hierarchy" for this kind of "digging". However, for the project I'm working on, it's very typical that the call hierarchy gets very big like this ("-"means called by): C-B | D-E-F | G-H-I | R-S-T-<test method> It's time consuming to dig into the tree and find the test method. Is there a better way/tool?Epicarp

© 2022 - 2024 — McMap. All rights reserved.