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

kt_jvm_test should infer the test_class if unspecified. #150

Closed
cgruber opened this issue Sep 19, 2018 · 7 comments · Fixed by #209
Closed

kt_jvm_test should infer the test_class if unspecified. #150

cgruber opened this issue Sep 19, 2018 · 7 comments · Fixed by #209

Comments

@cgruber
Copy link
Collaborator

cgruber commented Sep 19, 2018

If the rule is named FooTest and the test file is FooTest.java or FooTest.kt, and the test_class is unspecified, the test rule should just work out that the test_class is my.package.FooTest.

Note: it may be wrong if tests are specified differently in the .kt file, but that's totally fine, insofar as one can still override the test_class.

@cgruber cgruber changed the title kt_jvm_test should infer the test_class if unspecified. kt_jvm_test should infer the test_class if unspecified. Sep 19, 2018
@hsyed
Copy link
Contributor

hsyed commented Sep 19, 2018

Is it ok to just use the package name after translation directly ? My gut feel is that a normalising heuristic would be needed otherwise the java packages would need names like x.y.z.src.main.kotlin.com.acme.foo to line up with the default test_class name generated by the rule.

@cgruber
Copy link
Collaborator Author

cgruber commented Sep 21, 2018

Sadly it'll need normalizing.

Thankfully, the normalizing heuristic would probably would walking backwards to kotlin or java and chopping it off from there, as nearly all projects use src/main/java or src/main/kotlin. If those don't exist, src and test and maybe javatest as fallbacks.

The nice thing, is that this is an inferred default, so it can be wrong - you'll just end up specifying manually if you use a non-standard pattern for folder structure.

I'm not sure if it's possible to ingest the source files either, but if so, both java and kotlin declare "package" so that might also be a possibility.

@ZacSweers
Copy link

I think this is still broken, as I'm having to still specify a test_class to make tests work in this dagger PR: google/dagger#1805

@mgenov
Copy link

mgenov commented Oct 25, 2020

Seems broken. On my side I'm getting similar issue.

Class not found: [kotlin.com.mycompany.mypackage.MyClassUnderTest]
kt_jvm_test(
    name = "MyClassUnderTest",
    srcs = glob([
        "src/test/kotlin/**/*.kt",
        "src/test/kotlin/**/*.java",
    ]),
    deps = [
        ":utils_lib",
        "//kotlin/libs:test_lib_deps",
    ],
)

@nkoroste
Copy link
Collaborator

+1 broken for me as well.

My failure didn't even include the class name:

Class not found: []

@cgruber can you re-open this issue please?

@aryeh-looker
Copy link

+1

@aryeh-looker
Copy link

This can happen in my experience if the package name is left out from the test kt file

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

Successfully merging a pull request may close this issue.

6 participants