junit
2025/9/22小于 1 分钟约 136 字
参数化测试
static Stream<List<Long>> generateTestCustomerListGroup() {
return Stream.of(
List.of(1682023157700011596L, 1682023157700011603L),
List.of(1682023157700011596L, 1682023157700011603L,1L),
List.of(1682023157700011596L, 1L)
);
}
/**
* 使用方法提供数据
*/
@ParameterizedTest
@MethodSource("generateTestCustomerListGroup")
public void testExists(List<Long> customerIds) {
LambdaQueryWrapper<CustomerEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.in(CustomerEntity::getId, customerIds);
var inList = customerDao.selectCount(wrapper) == customerIds.size();
Assertions.assertTrue(inList, "存在不对应客服");
}
/**
* 使用csv 还可以CsvFileSource
*/
@ParameterizedTest
@CsvSource(value = {"1,2,3", "4,5,6"})
public void testAdd(int a, int b, int expected) {
Assertions.assertEquals(expected, a + b);
}动态测试
@TestFactory
public List<DynamicTest> test(){
return IntStream.range(0,5).boxed().map(i->{
return DynamicTest.dynamicTest("test"+i, () -> {
log.info("thread: {}", Thread.currentThread().getName());
Assertions.assertTrue( i>2,"hello");
});
}).toList();
}