ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[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); }); }); } ```