我想为返回ArrayList
的方法创建一个测试。 ArrayList
类型是一个名为DateItem
的自定义对象。但是当我尝试在我的测试代码(放在ArrayList
文件夹中)中创建test
时,测试失败并显示以下消息:
java.lang.OutOfMemoryError: GC overhead limit exceeded
Process finished with exit code 255
这是我的代码:
var expectedDateItems: ArrayList<DateItem> = ArrayList()
val currentDate = date1Start
while (currentDate.isBefore(date1End)) {
val dateItem = DateItem(currentDate, ArrayList())
expectedDateItems.add(dateItem)
currentDate.plusDays(1)
}
我想知道如何在我的测试代码中创建这样的ArrayList。我已经研究了this answer,但它适用于整个应用程序,不仅用于测试目的。如何为单元测试分配更多内存?
编辑:调试后,代码在此行中失败:val dateItem = DateItem(currentDate, ArrayList())
。
实际上你有无尽的WHILE循环,因为currentDate.plusDays(1)
返回copy的currentDate
。改成:
currentDate = currentDate.plusDays(1)