gpt4 book ai didi

java - getRequests() 必须返回一个可迭代的数组

转载 作者:搜寻专家 更新时间:2023-11-01 04:07:40 26 4
gpt4 key购买 nike

我的代码:

@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() 必须返回一个可迭代的数组

我如何运行参数化的 junit 并增加 int 作为输入参数?

假设对 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)

最佳答案

Junit 4.12+ 不再有此限制。因此,如果您使用 JUnit 4.12+ 开发测试,然后使用 4.11- 执行这些测试,您也会收到此错误消息。

参见 JUnit 4.12 release notes了解更多详情。

关于java - getRequests() 必须返回一个可迭代的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29950953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com