测试
最后更新于:2022-04-02 02:16:00
[TOC]
## 单元测试
```
dart
├── class
│ └── add.dart
├── pubspec.yaml
└── test
└── add_test.dart
```
```
//pubspec.yaml
name: dart1
description: A starting point for Dart libraries or applications.
dev_dependencies:
test: ^1.6.0
//add.dart
class add{
echo(num a,num b){
return a+b;
}
}
// add_test.dart
import 'package:test/test.dart';
import '../class/add.dart';
main(){
test("测试...", (){
// 测试 echo 方法
var a = add().echo(1, 2);
expect(a, 3);
});
}
```
## group 测试
```
//修改 add.dart
添加
echo2(num a,num b){
return a-b;
}
// add_test.dart
import 'package:test/test.dart';
import '../class/add.dart';
main(){
group("group 测试", (){
var a =add();
setUp((){
//进行测试前准备
//code
});
test("测试...", (){
var b1 =a.echo(2, 1);
var b2 =a.echo2(2, 1);
expect(b1, 3);
expect(b2, 1);
});
});
}
```
';