@RunWith(Parameterized.class)
public class FreshResultCompareRunner2 {
//This is called before @BeforeClass !
@Parameterized.Parameters
public static Collection getRequests() throws IOException {
injector = Guice.createInjector(new MainModule());
initStaticFromInjector();
initTestInput();
return OrganizeTestParameterizedInput();
}
private static void initTestInput() throws IOException {
}
private static Collection OrganizeTestParameterizedInput() {
Object[] objectMatrix = new Object[100];
for (int i = 0; i < 100; i++) {
objectMatrix[i] = i;
}
return Arrays.asList(objectMatrix);
}
返回以下异常:
getRequests() must return an Iterable of arrays
如何运行随int
仅作为输入参数的参数化的JUnit ?
说运行相同的测试为i=0 ...100
?
更新
我已经试过
//This is called before @BeforeClass !
@Parameterized.Parameters
public static Collection<int[]> getParameters() {
injector = Guice.createInjector(new MainModule());
initStaticFromInjector();
int numOfChunks = 3;//routingResponseShortRepository.getNumOfBaseLineChunks();
//might be less
int totalResponses = numOfChunks * globalSettings.requestsChunkSize;
Collection<int[]> params = new ArrayList<>(totalResponses);
for(int i = 1; i <= totalResponses; ++i) {
params.add(new int[] { i });
}
return params;
}
//takes the next matrix row from OrganizeTestParameterizedInput()
public FreshResultCompareRunner2(int responseId) {
this.responseId = responseId;
}
,仍然可以得到一个错误:
java.lang.Exception: com.waze.routing.automation.runners.FreshResultCompareRunner2.getParameters() must return an Iterable of arrays.
at org.junit.runners.Parameterized.parametersMethodReturnedWrongType(Parameterized.java:343)
请参阅我的更新。它仍然不起作用。 –
@EladBenda好的,我从内存编码 - 可能返回的集合必须是类型“集合
@EladBenda修复了代码。参数集的类型必须是Object []'。 – isnot2bad