weld / weld-testing

Set of test framework extensions (JUnit 4, JUnit 5, Spock) to enhance the testing of CDI components via Weld. Supports Weld 5.
http://weld.cdi-spec.org/
Apache License 2.0
102 stars 30 forks source link

Tests using @TempDir (junit5) fail with "Weld has failed to resolve test parameter" #143

Closed LukasLeppich closed 2 years ago

LukasLeppich commented 2 years ago

Test cases using the junit5 annotation @TempDir fail with the following error:

org.junit.jupiter.api.extension.ParameterResolutionException: Weld has failed to resolve test parameter [java.io.File arg0] in method [public void package.path.ClassTest.testMethod(java.io.File)].
Unsatisfied dependency has type java.io.File and qualifiers [].
 at org.jboss.weld.junit5.WeldJunit5Extension.supportsParameter([WeldJunit5Extension.java:172](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.ReferencePipeline$2$1.accept([ReferencePipeline.java:178](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.ReferencePipeline$3$1.accept([ReferencePipeline.java:197](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.ReferencePipeline$2$1.accept([ReferencePipeline.java:179](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining([ArrayList.java:1625](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.AbstractPipeline.copyInto([AbstractPipeline.java:509](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto([AbstractPipeline.java:499](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining([StreamSpliterators.java:310](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining([Streams.java:735](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining([Streams.java:734](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.AbstractPipeline.copyInto([AbstractPipeline.java:509](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto([AbstractPipeline.java:499](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential([ReduceOps.java:921](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.AbstractPipeline.evaluate([AbstractPipeline.java:234](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.stream.ReferencePipeline.collect([ReferencePipeline.java:682](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.ArrayList.forEach([ArrayList.java:1511](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.ArrayList.forEach([ArrayList.java:1511](vscode-file://vscode-app/c:/Users/lukas.leppich/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))

I created a simple test project to demonstrate this behavior: https://github.com/LukasLeppich/weld-testing-tempdir

manovotn commented 2 years ago

We try to resolve all parameters we can via Weld, that is a default setup so that users don't need to explicitly write annotations on all injection points. There is a way to disable this (even for a single test class if you like). @LukasLeppich take a look at this doc part and let me know if it solves yous issue - https://github.com/weld/weld-testing/tree/master/junit5#explicit-parameter-injection

LukasLeppich commented 2 years ago

I added the @ExplicitParamInjection annotation to all my test classes and no this error is gone, thank you!