Skip to content

[Java] Extract all unit test methods and the methods they call #15747

@xennygrimmato

Description

@xennygrimmato

I want to extract all unit test methods (Junit 4 or 5) and the corresponding methods that they test. I want to learn how to write a query for this.

Based on my current knowledge, I can do a from Call call and then add some heuristic-based checks on call.getCallee() and call.getCaller().

For example:

/**
 * @name Call graph
 * @description Call graph.
 * @kind problem
 * @id java/call-graph
 * @tags testability
 */

import java

// Track calls from test methods to other methods within the codebase.
from Call call
where call.getCaller().getName().matches("%test%")
select call.getCallee(), "calls", call.getCaller()

I get the following error:
Error was: Expected result pattern(s) are not present for problem query: Expected alternating entity/string and string columns. [INVALID_RESULT_PATTERNS]

What am I doing wrong here? Also, what would be a better way to write this query?

Metadata

Metadata

Assignees

No one assigned

    Labels

    JavaquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions