'JUnit parameterized test for median function
I am trying to write a JUnit test for a function that finds the median for a given array of double elements.
However, I am struggling with passing the parameters. My code looks like this:
@RunWith(Parameterized.class)
public class MedianParameterizedTest extends TestCase {
private Double[] numbers;
private Double expectedMedian;
public MedianParameterizedTest(Double[] numbers, double expectedMedian){
this.numbers = numbers;
this.expectedMedian = expectedMedian;
}
@Parameterized.Parameters
public static Collection medianArrays() {
return Arrays.asList(new Object[][] {
{ {-5.0,-4.0,3.0}, -4.0}
});
}
@Test
public void test1() {
//doing test
}
}
But this gives me an illegal initializer for java.lang.Object error for the medianArrays collection and I can't find out why.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
