我正在try 对一个类及其方法进行单元测试.方法通过forLoop中的工厂生成器方法生成对象列表.
-
单元测试我发现的方法通过返回堆栈溢出 destruct 了我的测试环境
-
如果我删除forloop,单元测试就会成功,没有任何问题
是什么导致了这一断裂?
final ClassA sut = ClassA();
// The suspect
void badMethod(
int arg1,
int arg2,
int arg3,
List<ClassA> ls,
) {
for (int i = arg1; i <= arg2; i + arg3) {
/// Below is a factory generator method from the Parent class,
/// being used in this subclass
ClassA t = ClassA.generate(type: 'test', trigger: i);
ls.add(t);
}
return;
}
// ----Test below
group('info', () {
// No problems here
test('test', () {
final List<ClassA> r = [];
ClassA t = ClassA.generate(type: 'test', trigger: i);
r.add(t);
expect(r, []);
});
//! stackoverflow here
test('adds object to list', () {
final List<Tile> r = [];
sut.badMethod(1, 1, 5, r); // <-- bad boy
expect(r, []);
expect(r.length, 0);
});
});