小编Fae*_*teh的帖子

junit5 无法识别 csv 文件

我正在尝试在 junit 5 的帮助下为一个类编写一些测试。我已经使用 Maven 导入了依赖项,但是当我尝试使用注释 @CsvFileSource(resources = "/testlist) 导入一个 csv 文件以用作测试用例时.csv") 我收到这个错误

org.junit.platform.commons.PreconditionViolationException: Classpath resource [/testlist.csv] does not exist
Run Code Online (Sandbox Code Playgroud)

这是我正在运行的代码

 package com.faezeh.shayesteh;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
public class MultipleOperationParamTest {
    @ParameterizedTest

    @CsvFileSource(resources = "/testlist.csv")
    void testMultipleOpWithCsvFileSrc(int operand, int data, int result){
        MultiplyOperation multop = new MultiplyOperation(operand);
        int actual = multop.operate(data);
        Assertions.assertEquals(result,actual);

    }
}
Run Code Online (Sandbox Code Playgroud)

这就是我的目录的排序方式 在此处输入图片说明

我需要提到当我不使用 Maven 作为框架并对我的目录进行如下排序时它工作正常并且没有问题 在此处输入图片说明

java junit maven junit5

2
推荐指数
1
解决办法
1219
查看次数

标签 统计

java ×1

junit ×1

junit5 ×1

maven ×1