-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Templated test contexts do not see transformed test classes (classloader/ordering issues in tests) #27821
Comments
I've updated the reproducer to remove some confusing package names. |
I've made the tests more comprehensive, which has given me some more data points.
Sad case:
Happy classloader: |
@stuartwdouglas reports that this issue is blocked on junit-team/junit5#2579. |
It looks like we may be able to resolve this in JUnit 5.10. If we didn't want to wait, a possible approach to handling this kind of problem (and various other problems related to JUnit seeing the un-transformed classes and XStream serialization not working with Java 17) is illustrated in Junit #1146. What they do is re-transform the classes in the JUnit extension. I don't think we want to do this, but it's nice to know the option there as a backup. What we get in JUnit 5.10 is junit-team/junit5#3091 (documentation). The docs say "A typical use case is to create a custom replace the ClassLoader used by the JUnit Platform to load test classes and engine implementations." (Hurray!) Further out is junit-team/junit5#3028, which allows richer classloader customisation. I think we won't need that, but if the |
When deciding if a test should be re-run we should also re-run the test if class level methods touched the changed class. Fixes quarkusio#27821
When deciding if a test should be re-run we should also re-run the test if class level methods touched the changed class. Fixes quarkusio#27821
When deciding if a test should be re-run we should also re-run the test if class level methods touched the changed class. Fixes quarkusio#27821
When deciding if a test should be re-run we should also re-run the test if class level methods touched the changed class. Fixes quarkusio#27821
Describe the bug
I think something is not right in classloading for test classes. If an extension transforms a test class, what gets executed is the transformed class (as you'd expect) - except that if the test is parameterised or uses a TestTemplate, the template gets passed a context which has the untransformed class.
For example, in this test,
MyContextProvider
gets handed a context which has the test class in it, loaded by theQuarkusClassLoader
, but un-transformed.Expected behavior
I would expect the view of the test class would be consistent across the whole test execution, including in the
ExtensionContext
.Actual behavior
The test above fails; the ExtensionContext has a version of the class which does not have transformations on it.
How to Reproduce?
Reproducer: https://github.com/holly-cummins/parameterized-test-reproducer/blob/main/README.md
What’s the reproducer doing? An extension defines some byte code transformations which apply to a test class.
The test uses a Junit 5 @testtemplate for tests. At runtime, the version of the test that runs is the version which was transformed by the extension. However, the ContextProvider for the test template is initialised with the non-transformed version of the test class (this is the problem).
Note that QuarkusDevModeTest may not seem to be enough to show this issue, it may need a proper integration testing running in dev mode. (I had another issue which definitely did not show up in the QuarkusDevModeTest but did with mvn Quarkus:dev.)
To see the failure,
To play with the failing test in more detail,
mvn verify
also fails.Output of
uname -a
orver
No response
Output of
java -version
openjdk version "17.0.2" 2022-01-18 OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8) OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Additional information
No response
The text was updated successfully, but these errors were encountered: