Ela*_*nda 3 java testing junit unit-testing parameterized
我的代码:
@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);
}
Run Code Online (Sandbox Code Playgroud)
返回以下异常:
getRequests() must return an Iterable of arrays
我如何运行参数化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;
}
Run Code Online (Sandbox Code Playgroud)
并仍然得到一个错误:
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)
Run Code Online (Sandbox Code Playgroud)
rmu*_*ler 10
Junit 4.12+不再具有此限制.因此,如果您使用JUnit 4.12+开发测试,然后使用4.11执行这些测试,您也会收到此错误消息.
有关更多详细信息,请参阅JUnit 4.12发行说明.
| 归档时间: |
|
| 查看次数: |
2858 次 |
| 最近记录: |