Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
136 views
in Technique[技术] by (71.8m points)

java - How can I define int[] as input and int as expected for @Parameters method ? Junit Test Case

I am writing a junit test case using parameters.

the input is an int array and output is int . What would be the method ? Can you please reply what would be the answer here ?

@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,0,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));
}
question from:https://stackoverflow.com/questions/65651021/how-can-i-define-int-as-input-and-int-as-expected-for-parameters-method-jun

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...