Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect test target selected when running or debugging tests with Bazel for IntelliJ plugin versions 2023.10.08.0.1 and newer #7017

Open
paulxu86 opened this issue Nov 19, 2024 · 2 comments
Assignees
Labels
awaiting-maintainer Awaiting review from Bazel team on issues product: IntelliJ IntelliJ plugin type: bug

Comments

@paulxu86
Copy link

Description of the bug:

When running or debugging tests in IntelliJ IDEA using newer versions of the Bazel for IntelliJ plugin (versions 2024.10.08.0.1-api-version-242 and later), the IDE often selects the incorrect Bazel target for test execution. I have noticed that this issue specifically occurs when a test class extends a base test class. While it may happen in other scenarios, this appears to be a common case.

Which category does this issue belong to?

Intellij

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  1. Set up the environment:

  2. Open a Bazel project in IntelliJ IDEA.

  3. Find a test class that extends another base test class:

public class TestA extends OtherBaseTestB {
    // Test implementation
}
  1. Attempt to run or debug the test:
    Click the green run/debug icon (▶) next to the test class in the editor's left gutter.

  2. Observe the behaviour:

    • The IDE selects the wrong Bazel target for the test execution.
    • Tests may fail or produce unexpected results due to the incorrect target being used.

Which Intellij IDE are you using? Please provide the specific version.

IntelliJ IDEA Ultimate Edition [2024.2] and [2024.3]

What programming languages and tools are you using? Please provide specific versions.

Programming Language: Java; Test Frameworks: JUnit; Bazel Version: 7.2.1

What Bazel plugin version are you using?

2024.10.08.0.1-api-version-242, 2024.11.07.0.1-api-version-243

Have you found anything relevant by searching the web?

GitHub Issues: Searched but did not find existing issues related to this problem.
Email Threads: Checked the intellij-bazel-plugin Google Group as well but found no relevant discussions.

Any other information, logs, or outputs that you want to share?

  • The issue seems to be specifically related to test classes that extend to other classes. The log (in IntelliJ "Run" window) will show no tests were found because the test ran on the wrong target.
  • No error messages are displayed; the tests simply run against the incorrect target.
  • Reverting to the older plugin version (2023.09.24.0.3-api-version-242) resolves the issue.
@paulxu86
Copy link
Author

I wanted to provide some additional details that might help diagnose the issue.

In our project, we use list expansion in our <MODULE_NAME>/BUILD.bazel files to dynamically execute the test targets. I suspect this might be contributing to the problem with incorrect test target selection in the newer plugin versions.

Here's a simplified and sanitized snippet of our BUILD.bazel file for TestA:

load("@rules_java//java:defs.bzl", "java_junit5_test")

package(default_visibility = ["//visibility:public"])

java_library(
    name = "my_project_lib",
    srcs = glob(["src/main/java/**/*.java"]),
    deps = [
        # Dependencies
    ],
)

TEST_FILES = glob(
    ["src/test/java/**/*.java"],
)

# test targets using list expansion
[java_junit5_test(
    name = "test_" + f[:-5].replace("/", "_").replace("src_test_java_", ""),
    srcs = [f],
    test_class = f[:-5].replace("/", ".").replace("src.test.java.", ""),
    deps = [
        ":my_project_lib",
        "//thirdparty:junit5-jupiter",
        # Other dependencies
    ],
    # Other attributes
) for f in TEST_FILES]

As I mentioned in the description above, running a test class (e.g., TestA), that extends OtherBaseTestB, the plugin selects the wrong Bazel target. The plugin incorrectly selects the target AnotherBaseTestC, which is incorrect. If we stick with using the plugin with the newer version, we need to manually edit the Run/Debug Configuration window to specify the correct target for TestA.

I hope this additional information helps in identifying the root cause of the issue.

@tpasternak
Copy link
Collaborator

Well, looks like related to this change #4473

@agluszak can you please look at it?

@tpasternak tpasternak assigned agluszak and unassigned tpasternak and mai93 Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-maintainer Awaiting review from Bazel team on issues product: IntelliJ IntelliJ plugin type: bug
Projects
Status: Untriaged
Development

No branches or pull requests

4 participants