Skip to main content
Version: 10.x

Collections and Arrays

AutoParams can generate collections and arrays automatically. By default, the size of generated collections and arrays is 3, but you can override this using annotations such as @Size.

For example, the following tests verify that AutoParams generates an ArrayList<String> and a String[] with exactly 5 elements when the @Size(min = 5) constraint is applied:

@Test
@AutoParams
void testMethod(@Size(min = 5) ArrayList<String> arrayList) {
assertThat(arrayList).hasSize(5);
}
@Test
@AutoParams
void testMethod(@Size(min = 5) String[] array) {
assertThat(array).hasSize(5);
}

This allows you to work with realistic data sizes while keeping your test code clean and concise.