JUnit5针对不同参数的多个来源笛卡尔积

问题描述

我试图用JUnit 5编写一个测试,该测试应该测试某些参数的多个组合。本质上,我想测试来自不同来源的输入的某些笛卡尔积。考虑以下测试:

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
class CartesianProductTest {

    @ParameterizedTest
    @CsvFileSource(resources = { "values.csv" })
    void testIt(int input,int expected,int otherParameter) {
        assertEquals(expected,methodUnderTest(input,otherParameter));
    }
}

现在的问题是,我在input中只有expectedvalues.csv,应该测试otherParameter的某些固定值,methodUndertest()总是返回所有这些值的期望值。我必须以某种方式提供CSV中所有值和otherParameter可以取的所有值的笛卡尔乘积。我看着https://stackoverflow.com/a/57648088/7962200,但这需要对所有测试用例进行硬编码或手动读取CSV以提供值流。我想更多类似的东西

import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvFileSource;
class CartesianProductTest {

    @ParameterizedTest
    @MethodSource
    void testIt(int input,otherParameter));
    }

    static Stream<Arguments> testIt() {
         return csvValues().flatMap(csv ->
             otherParams().map(otherParam -> Arguments.of(csv,otherParam)));
    }

    @CsvFileSource(resources = { "values.csv" })
    static Stream<Arguments> csvValues() {/* get somehow from Annotation */}
    @CsvFileSource(resources = { "otherparam.csv" })
    static Stream<Arguments> otherParams() {/* get somehow from Annotation */}
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...