Skip to main content
Version: 11.x

Overview

AutoParams is a JUnit 5 extension for automatic test data generation, inspired by AutoFixture.

Manually creating test data is often repetitive and distracts from the core logic of the test. AutoParams eliminates this boilerplate by supplying automatically generated values to your test method parameters, allowing you to write concise and focused tests.

Getting started is simple: annotate your @Test method with @AutoParams(or @AutoKotlinParams in Kotlin), and the parameters will be populated with generated data.

@Test
@AutoParams
void testMethod(int a, int b) {
Calculator sut = new Calculator();
int actual = sut.add(a, b);
assertEquals(a + b, actual);
}

In the example above, a and b are automatically generated, making the test cleaner and reducing the need for manual setup or value triangulation.

AutoParams also supports more advanced scenarios. When multiple generated values need to share a reference—such as reviews referring to the same product—you can use the @Freeze annotation to ensure consistency.

@AllArgsConstructor
@Getter
public class Product {

private final UUID id;
private final String name;
private final BigDecimal priceAmount;
}
@AllArgsConstructor
@Getter
public class Review {

private final UUID id;
private final UUID reviewerId;
private final Product product;
private final int rating;
private final String comment;
}
@Test
@AutoParams
void testMethod(@Freeze Product product, Review[] reviews) {
for (Review review : reviews) {
assertSame(product, review.getProduct());
}
}

This ensures that all generated Review instances refer to the same frozen Product, simplifying test setup in scenarios involving shared dependencies.