Skip to content

JUnit-import excludes non-test production code, dropping its call expressions #68

Description

@Ridwanul-OpenRefactory

CallGraphProcessor treats any file that imports org.junit.* / junit.* as a test file and excludes it from analysis before the call graph is built.
A bare import is not evidence that a file is a test - every such file is silently dropped: none of its methods are registered and so every call into it from real production code resolves to nothing - no source edge, no library edge. The call simply vanishes from the graph.

This is the general form of the problem reported in issue #66 which covers only the special case where the file's own package is org.junit/junit (i.e. JUnit itself).


Root cause

CallGraphProcessor.getImports (CallGraphProcessor.java) raises the flag on the import string alone:

// To cover all type of junit packages, we added these 2 conditions.
// Previously we used to maintain a list containing test packages.
if (importString.toString().startsWith("org.junit")
        || importString.toString().startsWith("junit")) {
    hasJUnitImport = true;
}

buildCallGraph, phase 1 (CallGraphProcessor.java), excludes the file outright when that flag is set - the import signal is ORed with the directory signal:

if (cgPhase == Phase.PHASE_1
        && (!ConfigurationManager.isTestRun
                && (importsPair.snd || CallGraphUtility.isUnderTestOrExampleDirectory(filePath)))) {
    CallGraphDataStructures.addFileToExcludedList(filePath);
    ...
}

We need to figure out a proper way to handle such cases where a file imports junit because such files are always excluded from call-graph creation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions