Dart ট্র্যাকে টেস্টিং

Exercism-এ আপনার Dart অনুশীলনী কীভাবে টেস্ট করবেন তা জানুন


একটি অনুশীলনী ডাউনলোড করা

আপনি যে অনুশীলনীতে কাজ করতে চান, সেটি ডাউনলোড করতে Exercism CLI ব্যবহার করুন।

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

এরপর অনুশীলনীর ডিরেক্টরিতে চলে যান।

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

ডিপেন্ডেন্সি ইনস্টল করা

Test চালানোর আগে অনুশীলনীর ডিপেন্ডেন্সিগুলো ডাউনলোড করে নিন।

dart pub get

Test চালানো

dart test

Test-এর ফলাফল বোঝা

dart test ডিফল্টভাবে compact reporter ব্যবহার করে, যা এক লাইনে পাস, স্কিপ ও ফেল হওয়া Test-এর চলমান হিসাব দেখায়।

$ 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: ১টি Test পাস হয়েছে
  • ~9: ৯টি Test স্কিপ হয়েছে
  • -1: ১টি Test ফেল হয়েছে

প্রতিটি Test-এর আরও বিস্তারিত আউটপুট পেতে চাইলে expanded reporter ব্যবহার করুন, যা চালানোর সময় প্রতিটি Test-এর ফলাফল দেখায়।

$ 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.

Test-গুলো একে একে করা

বেশিরভাগ অনুশীলনীতেই একাধিক Test থাকে, আর প্রথমটি ছাড়া বাকি সবগুলো ডিফল্টভাবে স্কিপ করা থাকে।

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);
  });
}

একে একে Test করতে করতে, প্রতিটি Test-এ skip: true-এর জায়গায় skip: false করে নিন। অথবা ফাইলটি এডিট না করেই সব Test একবারে চালিয়ে দিন।

dart test --run-skipped

সাবমিট করার সময় অনলাইন test runner সব Test চালায়, স্কিপ করা Test-গুলোসহ।

এরর "Could not find a command named frontend_server.dart.snapshot" সামলানো

ধরা যাক, একটি অনুশীলনী আপনি আগেই সমাধান করে সাবমিট করেছেন, আর কিছুদিন পর আবার সেটিতে ফিরে এসেছেন। সেটি Test করার সময় আপনি এই এররটির মুখোমুখি হতে পারেন:

$ dart test
...
Could not find a command named "/path/to/frontend_server.dart.snapshot".

এর সমাধান হলো pubspec.lock ফাইলটি মুছে ফেলা। তারপর আবার dart কমান্ডটি চালান।