Pri*_*ick 8 dart flutter flutter-test
我想测试的单元代码:
imports ...
class TextHolder extends StatelessWidget{
const TextHolder({
Key key,
@required this.text
}) : assert (text != null),
super(key: Key);
@override
Widget build(BuildContext context) {
return Text(text);
}
}
Run Code Online (Sandbox Code Playgroud)
当我编写测试代码时:
imports ...
void main(){
test('Assert Null check', (){
// tried this
expect(TextHolder(text: null), throwsAssertionError);
// also this
final Matcher throwsAssertionError = throwsA(isA<AssertionError>());
expect(TextHolder(text: null), throwsAssertionError);
});
}
Run Code Online (Sandbox Code Playgroud)
无法Failed assertion使用 flutter_test 包执行测试。当我运行测试代码时,我在控制台中收到类似以下内容的错误:
Failed assertion: line 8 pos 16: 'text != null': is not true.
我在寻找什么:
@required如果有人从我的单元代码中删除注释,我的测试用例应该会失败。null值,我的测试用例应该失败textKol*_*gaR 12
test('Assert Null check', (){
expect(() { TextHolder(text: null) }, throwsAssertionError);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3542 次 |
| 最近记录: |