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

java.lang.NoSuchMethodError with version 2.0.3 #65

Closed
thees opened this issue Jan 16, 2019 · 2 comments
Closed

java.lang.NoSuchMethodError with version 2.0.3 #65

thees opened this issue Jan 16, 2019 · 2 comments

Comments

@thees
Copy link

thees commented Jan 16, 2019

I get a java.lang.NoSuchMethodError when I use version 2.0.3. With version 1.5.2 it works.
Using gradle 5.0 or 5.1

My test (in a testset 'functionalTest') uses a function in a package (i.e. not in a class; to create a common test object) like this:

@Test
fun `test insert into db`() {
    assertTimeout(Duration.ofSeconds(7L)) {
        insertObjectIntoDb(aTestObject())
        ...
    }
}

where aTestObject is defined in another kotlin file (also in the same testset):

package com.xyz.company.databasetest

import ...

internal fun aTestObject(version: Long = 1L): TestObject {
    return TestObject(
        id = "id",
        version = version
    )
}

when I run the functionalTests on command line the test fails with a NoSuchMethodError saying that aTestObject method cannot be found.
The error also occurs when I put the argument explicitly in the test (ignoring the default argument in aTestObject method)

    java.lang.NoSuchMethodError: com.xyz.company....TestObjectsKt.aTestObject(J)Lcom/xyz/company/.../TestObject;
        at com.....TestObjectTest$test insert into db$1.execute(TestObjectTest.kt:63)
        at org.junit.jupiter.api.AssertTimeout.lambda$assertTimeout$0(AssertTimeout.java:49)
        at org.junit.jupiter.api.AssertTimeout.assertTimeout(AssertTimeout.java:78)
        at org.junit.jupiter.api.AssertTimeout.assertTimeout(AssertTimeout.java:66)
        at org.junit.jupiter.api.AssertTimeout.assertTimeout(AssertTimeout.java:48)
        at org.junit.jupiter.api.AssertTimeout.assertTimeout(AssertTimeout.java:44)

Strangely the test runs in IntelliJ.

Maybe the error occurs, because the test uses Junit5 "assertTimeout"?

@tkrullmann
Copy link
Member

Hi, I've tried to recreate this and couldn't reproduce the error.

If it's working when running the test from IntelliJ, it might mean that the TestObjectKt wrapper class around your function isn't on the test classpath (because IntellIJ test runner manages its own classpath).

Could you please

  • check if it's working with the latest version 2.1.0 (there were some fixes to the classpath)
  • if it still fails, log the test testClassesDirs and classpath e.g. like this:
tasks.withType<Test> {
    doFirst {
        println ("""
            Test task "$name":
              testClassesDirs: ${testClassesDirs.joinToString()}
              classpath: ${classpath.joinToString()}
        """.trimIndent())
    }
}

The testClassesDirs should have two entries: the directories that end with build/classes/java/functionalTest and build/classes/kotlin/functionalTest.

These two should also be in the classpath.

BTW assertTimeout shouldn't be the issue, it's only on the stacktrace because it's executing the lambda argument.

@thees
Copy link
Author

thees commented Jan 26, 2019

Hi @tkrullmann ,
I can verify that the bug has been fixed with 2.1.0. I also retested with the old version 2.0.3 where the bug still occured, just to be sure ;-)

Thanks,
Sebastian

@thees thees closed this as completed Jan 26, 2019
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

2 participants