Tesztelés a Dart-kurzuson

Tanuld meg, hogyan teszteld a Dart-feladataidat az Exercism-ön.


Feladat letöltése

Az Exercism CLI segítségével töltsd le azt a feladatot, amelyen dolgozni szeretnél.

exercism download --track=dart --exercise=hello-world

Ezután lépj be a feladat könyvtárába.

cd /path/to/exercism/dart/hello-world

Függőségek telepítése

Mielőtt futtatod a teszteket, töltsd le a feladat függőségeit.

dart pub get

A tesztek futtatása

dart test

A teszteredmények értelmezése

A dart test alapértelmezés szerint a tömör riportert használja, amely egyetlen sorban mutatja a sikeres, kihagyott és sikertelen tesztek futó darabszámát.

$ dart test
00:00 +1 -1: test/binary_search_test.dart: finds a value in the middle of an array [E]
  Expected: <3>
    Actual: <0>

  package:matcher                    expect
  test/binary_search_test.dart 13:5  main.<fn>


To run this test again: dart test test/binary_search_test.dart -p vm --plain-name 'finds a value in the middle of an array'
00:00 +1 ~9 -1: Some tests failed.
  • +1: 1 sikeres teszt
  • ~9: 9 kihagyott teszt
  • -1: 1 sikertelen teszt

Ha részletesebb, tesztenkénti kimenetre van szükséged, használd a bővített riportert, amely futás közben mutatja az egyes tesztek eredményét.

$ dart test -r expanded
00:00 +0: loading test/binary_search_test.dart
00:00 +0: test/binary_search_test.dart: finds a value in an array with one element
00:00 +1: test/binary_search_test.dart: finds a value in the middle of an array
00:00 +1 -1: test/binary_search_test.dart: finds a value in the middle of an array [E]
  Expected: <3>
    Actual: <0>
  
  package:matcher                    expect
  test/binary_search_test.dart 13:5  main.<fn>
  
00:00 +1 -1: test/binary_search_test.dart: finds a value at the beginning of an array
00:00 +1 ~1 -1: test/binary_search_test.dart: finds a value at the end of an array
00:00 +1 ~2 -1: test/binary_search_test.dart: finds a value in an array of odd length
00:00 +1 ~3 -1: test/binary_search_test.dart: finds a value in an array of even length
00:00 +1 ~4 -1: test/binary_search_test.dart: identifies that a value is not included in the array
00:00 +1 ~5 -1: test/binary_search_test.dart: a value smaller than the array's smallest value is not found
00:00 +1 ~6 -1: test/binary_search_test.dart: a value larger than the array's largest value is not found
00:00 +1 ~7 -1: test/binary_search_test.dart: nothing is found in an empty array
00:00 +1 ~8 -1: test/binary_search_test.dart: nothing is found when the left and right bounds cross
00:00 +1 ~9 -1: Some tests failed.

Haladás a tesztekkel

A legtöbb feladatban több teszt van, és alapértelmezés szerint az első kivételével mindegyik ki van hagyva.

void main() {
  final twoFer = TwoFer();

  group('TwoFer', () {
    test('no name given', () {
      final result = twoFer.statement();
      expect(result, equals('One for you, one for me.'));
    }, skip: false);

    test('a name given', () {
      final result = twoFer.statement('Alice');
      expect(result, equals('One for Alice, one for me.'));
    }, skip: true);

    test('another name given', () {
      final result = twoFer.statement('Bob');
      expect(result, equals('One for Bob, one for me.'));
    }, skip: true);
  });
}

Ha egyszerre csak egy teszttel szeretnél haladni, sorban változtasd meg minden teszten a skip: true értéket skip: false-ra. Vagy futtasd le az összes tesztet egyszerre anélkül, hogy szerkesztenéd a fájlt.

dart test --run-skipped

Beküldéskor az online tesztfuttató az összes tesztet lefuttatja, a kihagyottakat is.