I am getting below exception while using @ParameterizedTest with @CsvFileSource, even though the JunitTest.csv file is present in src/test/resources.
Can someone help on this?
Test Method:
@ParameterizedTest
@CsvFileSource(resources = "/JuntTest.csv")
void testCsvFileSource(String col1, String col2, String col3){
System.out.println("Column1: "+col1+" Column2: "+col2+" Column3: "+col3);
}
Maven Dependencies:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.jupiter.version>5.1.0</junit.jupiter.version>
<junit.vintage.version>5.1.0</junit.vintage.version>
<junit.platform.version>1.1.0</junit.platform.version>
</properties>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
Exception:
org.junit.platform.commons.util.PreconditionViolationException: Classpath resource does not exist: /JuntTest.csv
at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:297)
at org.junit.platform.commons.util.Preconditions.notNull(Preconditions.java:69)
at org.junit.jupiter.params.provider.CsvFileArgumentsProvider.openInputStream(CsvFileArgumentsProvider.java:78)
at org.junit.jupiter.params.provider.CsvFileArgumentsProvider.lambda$provideArguments$0(CsvFileArgumentsProvider.java:70)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.execute(TestTemplateTestDescriptor.java:101)
at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.execute(TestTemplateTestDescriptor.java:38)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:112)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:120)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:120)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:120)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:120)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:55)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:65)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Suppressed: org.junit.platform.commons.util.PreconditionViolationException: Configuration error: You must provide at least one argument for this @ParameterizedTest
at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:297)
at org.junit.jupiter.params.ParameterizedTestExtension.lambda$provideTestTemplateInvocationContexts$7(ParameterizedTestExtension.java:60)
at java.util.stream.AbstractPipeline.close(AbstractPipeline.java:323)
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271)
... 52 more
This is probably better question for Stack Overflow, but the exception message looks fairly clear
Classpath resource does not exist: /JuntTest.csv
Closing due to lack of activity. Please reopen if the issue persists.
I am also seeing this. If I have testCompile "org.junit.jupiter:junit-jupiter-params:5.0.1" in my gradle dependencies, the following test fails (needless to say, test.csv is present in the resources directory):
@Test
void test() throws Exception {
InputStream resource = GenericCsvReaderFactoryTest.class
.getClassLoader()
.getResourceAsStream("test.csv");
assertThat(resource).isNotNull();
}
If the dependency is removed the test passes.
Please reopen this! Thanks
Are you sure the presence of junit-jupiter-params on the classpath changes the result of your test?
Yes, when it's there the test fails, when absent the test passes.
Could you please provide a sample project so we can see that with our own eyes? 馃槻
Yes, please do provide a sample project that reproduces this behavior.
I'd also like to see it (and debug it) with my own eyes. 馃槈
OK, will do.
So digging into this I suspect some interaction between intellij/spring/junit classloaders. I can't reproduce it in a simple project, and it seems to behave inconsistently in idea also. In my big (multi-module, spring-up-the-wazoo dependencies) it's relatively easy to reproduce, but not (so far) in my 1-class harness.
As you were, then: if I do work out what's going on I'll post back here. Thanks for the responses.
Smells like a component setting the TCCL to an instance that does not longer have the "resources" path in its classpath or the test.csv is not copied to the runtime version of the resources directory.
Or something completely different... (-:
FYI I'm now sure this is an intellij issue.
@davethehat, thanks for confirming that this is not an issue with JUnit Jupiter!
I am re-closing this issue.
@sbrannen @marcphilipp I experience the same issue, BUT no Intellij here: I set up java and maven on a CentOS7 separate machine and ran tests with _mvn test_ Same issue: org.junit.platform.commons.util.PreconditionViolationException: Classpath resource [/my_file] does not exist
@dmytrocx75 Please provide a sample project so we can reproduce the issue.
@marcphilipp Here you go https://github.com/dmytrocx75/asustest
@dmytrocx75, the problem is that Users.csv must be a classpath resource, but since you have it in src/test/java, Maven does not copy it to the target classpath folder.
The solution to your problem is simply to move Users.csv to src/test/resources.
I tested that locally, and it works as expected.
@dmytrocx75, here are the results:
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestClass
Before allInside test1Inside test2Ann ann
Cate k
Pet pet
After all[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.188 s - in TestClass
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
[INFO]
You're right. Sorry, I jumped the gun.
I also have this problem. If I copy the csv files to the bin/test directory, the tests work.
I am using Eclipse Oxygen and the project does not use Maven or Gradle.
I also have this problem. If I copy the csv files to the bin/test directory, the tests work.
I am using Eclipse Oxygen and the project does not use Maven or Gradle.
You have to make sure that the folder that contains your CSV file is marked as a Source Folder in Eclipse.
... for example, right click on the folder and then select _Build Path_ -> _Use as Source Folder_.
it happens even when I do that
it happens even when I do that
Are you able to share your Eclispe .classpath file (potentially changing confidential paths/information)?
I faced similar issue as soon as I moved Acceptance test classes under test directory it is resolved.
Most helpful comment
You're right. Sorry, I jumped the gun.