0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dart の assertion テスト

0
Last updated at Posted at 2020-10-11

Class のインスタンス生成時における assert のテスト

  • テスト対象は、ブロックで渡す
  • 実行結果は、エラーオブジェクトのクラスを検証する

テスト対象

class Article {
  Article({this.title})
      : assert(title != null);

  String title;
}

assert テスト

test('Case null member', () {
  expect(() {
    Article(title: null);
  }, throwsA(isA<AssertionError>()));
});

間違った記述例

test('Case null member', () {
  var article = Article(title: null);

  expect(article, AssertionError);
});


test('Case null member', () {
  var article = Article(title: null);

  expect(() {
    article;
  }, throwsA(isA<AssertionError>()));
});
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?