10 单元测试

测试类方法:

num sum(num num1, num num2) {
  return num1 + num2;
}

num mul(num num1, num num2) {
  return num1 * num2;
}

测试类文件:

/// 单元测试
void main() {
  group("test math utils file", () {
    test("test math utils sum file", () {
      final result = sum(10, 20);
      expect(result, 30);
    });
    test("test math utils mul file", () {
      final result = mul(9, 12);
      expect(result, 108);
    });
  });
}

Widget测试:

/// widget 测试
void main() {
  testWidgets("contact test", (WidgetTester tester) async {
    await tester.pumpWidget(ContactPage(names: ["David", "Tom", "Jack"]));

    expect(find.text("Jack"), findsOneWidget);
    expect(find.text("David"), findsOneWidget);
    expect(find.text("David2"), findsNothing);
    expect(find.byIcon(Icons.people), findsNWidgets(3));
  });
}

你可能感兴趣的:(10 单元测试)