Open paulxu86 opened 2 days ago
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.
Well, looks like related to this change https://github.com/bazelbuild/intellij/pull/4473
@agluszak can you please look at it?
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.
Set up the environment:
Open a Bazel project in IntelliJ IDEA.
Find a test class that extends another base test class:
Attempt to run or debug the test: Click the green run/debug icon (▶) next to the test class in the editor's left gutter.
Observe the behaviour:
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?