-2
List<List<T>>
에있는 모든 요소의 길이가 0 인 테스트를 위해 자체 Matcher를 구현했습니다. 테스트는 약간 자세한 정보로 보이며 단순화하는 방법이 있는지 궁금합니다. everyElement에 대한 인수는 matcher
이름 만입니다Matcher를 단순화하는 방법
void main() {
Board board = new Board(10,10); // board.pieces is a List<List<Piece>>
test('All pieces have a length of 0',() => expect(board.pieces,everyElement(length)));
}
class LengthMatcher extends Matcher {
final int _length;
LengthMatcher(this._length);
bool matches(item, Map matchState) => item is List && item.length==_length;
Description describe(Description description) => description.add('A List with a length of $_length');
}
LengthMatcher length = new LengthMatcher(0);