Classpath resource [data/department/createDepartment.csv] does not exist

一、问题现象

  在做自动化的时候,想使用参数化功能,数据源为CSV,但是遇到以下问题

Classpath resource [data/department/createDepartment.csv] does not exist
org.junit.platform.commons.PreconditionViolationException: Classpath resource [data/department/createDepartment.csv] does not exist

    at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:296)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
    Suppressed: org.junit.platform.commons.PreconditionViolationException: Configuration error: You must configure at least one set of arguments for this @ParameterizedTest
        at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:281)
        at org.junit.jupiter.params.ParameterizedTestExtension.lambda$provideTestTemplateInvocationContexts$6(ParameterizedTestExtension.java:90)
        at java.util.stream.AbstractPipeline.close(AbstractPipeline.java:323)
        at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271)
        ... 49 more

二、问题定位

  maven项目的classPath路径下没有文件/data/department/createDepartment.csv,即maven的classPath在 “target\classes”目录下

三、原因分析

maven默认只会加载classPath同级目录下文件,其他的需要重新设置

四、解决方案

1、选中项目工程,右键,选择Open  Moudle Settings,选择Resources,点击apply

Classpath resource [data/department/createDepartment.csv] does not exist

  ===========================================================================================

Classpath resource [data/department/createDepartment.csv] does not exist

2、在pom文件的bulid标签配置<resources>(极力推荐)

        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <!--是否替换资源中的属性-->
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                    <include>**/Dockerfile</include>
                    <include>**/*.xlsx</include>
                    <include>**/*.csv</include>
                </includes>
                <!--是否替换资源中的属性-->
                <filtering>false</filtering>
            </resource>
        </resources>

五、总结

  此种问题,是因为还不够了解maven,看来还是需要多研究研究

 

推荐博客:

maven打包resources配置

maven resources官网

Classpath resource [data/department/createDepartment.csv] does not exist

上一篇:常用函数


下一篇:机器视觉-使用opencv将人像抠出来,加上纯色背景图