如何将 int[] 定义为 @Parameters 方法的预期输入和 int ? Junit 测试用例

问题描述

我正在使用参数编写一个 junit 测试用例。

输入是一个 int 数组,输出是 int 。方法是什么? 你能回复这里的答案吗?

@RunWith(Parameterized.class)
public class TestingJunitClasstest {

TestingJunitClass testJunitObject;
private int[] input;
private int expectedOutput;

public TestingJunitClasstest(int[] input,int expectedOutput) {
    this.input = input;
    this.expectedOutput = expectedOutput;
}

@Before
public void init() {
    System.out.println("Running before every test");
    testJunitObject = new TestingJunitClass();
}

@Parameters
public static List<Object[][]> testConditions() {
    return Arrays.asList(new Object[][] {{{4,8,7,3},8},{{10,25,35,4},35}});  //gives error Type mismatch: cannot convert from int[] to Object
}

@Test
public void testGetMaxnumbersForPositiveIntegers() {
    assertEquals(expectedOutput,testJunitObject.getMaxnumber(input));
}

解决方法

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

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

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

相关问答

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