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

@Suite test_class not picking up matching selected classes. #206

Closed
mathieu-stennier opened this issue Sep 7, 2023 · 1 comment
Closed

Comments

@mathieu-stennier
Copy link

mathieu-stennier commented Sep 7, 2023

I have the following UnitTestSuite.java file

@Suite
@IncludeClassNamePatterns("^(Test.*|.+[.$]Test.*|.*Tests?)$")
public class UnitTestSuite {}

And following macro

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

def java_unit_test(name, srcs, deps, **kwargs):
    java_junit5_test(
        name = name,
        test_class = "com.foo.testsuite.UnitTestSuite",
        srcs = srcs + ["//tools/test/java/testsuite:src/main/java/com/foo/testsuite/UnitTestSuite.java"],
        runtime_deps = [
            "@maven//:org_junit_platform_junit_platform_runner",
            "@maven//:org_junit_platform_junit_platform_reporting",
        ],
        deps = deps + ["@maven//:org_junit_platform_junit_platform_suite_api"],
        **kwargs
    )

called with

java_unit_test(
    name = "unit_test",
    srcs = glob(["src/test/java/com/foo/**/*UnitTest.java"]),
    deps = [
        ":base_gateway",
        "@maven//:org_junit_jupiter_junit_jupiter_api",
        "@maven//:org_junit_jupiter_junit_jupiter_engine",
    ],
)

and

public class FooUnitTest {
  @Test
  public void test() {
    Assertions.assertEquals(0, 2);
  }

  @Test
  public void test3() {
    Assertions.assertEquals(0, 2);
  }
}

When I run bazel test //foo:unit_test it seems that it is only running the actual UnitTestSuite without executing the other suite classes matching the pattern and provided in srcs.

Is there something wrong?

I used to be able to do that using native.java_test and previous @Suite() / @SuiteClasses.

If I add a test in UnitTestSuite:

@Suite
@IncludeClassNamePatterns("^(Test.*|.+[.$]Test.*|.*Tests?)$")
public class UnitTestSuite {
  @Test
  public void test() {
    Assertions.assertEquals(0, 2);
  }
}

then test is correctly run and fails:

INFO: Analyzed target //foo/base:unit_test (0 packages loaded, 0 targets configured).
INFO: Found 1 test target...
...
INFO: Elapsed time: 1.034s, Critical Path: 0.95s
INFO: 3 processes: 1 internal, 1 darwin-sandbox, 1 worker.
INFO: Build completed, 1 test FAILED, 3 total actions
//foo/base:unit_test                                       FAILED in 0.8s
...
expected: <0> but was: <2>
Expected :<0>
Actual   :<2>
Executed 1 out of 1 test: 1 fails locally.

Thanks for your help

@mathieu-stennier
Copy link
Author

Closing the issue as I found the error myself. Nothing to do with this library.

Just adding

@Suite
@SelectPackages("com.foo")
@IncludeClassNamePatterns(".*UnitTest.*")
public class UnitTestSuite {}

worked. Didn't know we had to select things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant