2014-07-08 3 views
-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); 

답변

1

은 어떤 유형이 없습니다 때문에 dynamic입니다.
지원되는 matchers 및 함수입니다.

import 'package:unittest/unittest.dart'; 
import 'package:matcher/matcher.dart'; 

void main(args) { 
    List<List<int>> board = [[],[],[],[],[],[],[],[],[],[]]; 

    test('',() { 
    expect(board, everyElement((List e) => e is List && e.length == 0)); 
    }); 
} 
관련 문제