0
0
Fluttermobile~10 mins

Unit testing in Flutter - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Flutter test package.

Flutter
import 'package:flutter_test/[1]';
Drag options to blanks, or click blank then click option'
Aflutter_test.dart
Bflutter
Ctest
Dflutter_test
Attempts:
3 left
💡 Hint
Common Mistakes
Adding '.dart' extension in the import path.
Using 'test' package instead of 'flutter_test'.
2fill in blank
medium

Complete the code to define a test case with description 'adds two numbers'.

Flutter
test('[1]', () {
  expect(1 + 1, 2);
});
Drag options to blanks, or click blank then click option'
Aadds two numbers
Btest addition
Ccheck addition
Dsum test
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different test description string.
Omitting the test description.
3fill in blank
hard

Fix the error in the test to correctly check if the result equals 5.

Flutter
test('check result', () {
  var result = 2 + 3;
  expect(result, [1]);
});
Drag options to blanks, or click blank then click option'
AisEqualTo(5)
Bequals(5)
C5
DequalTo(5)
Attempts:
3 left
💡 Hint
Common Mistakes
Using matcher functions like equals(5) which are not needed here.
Passing a string instead of a number.
4fill in blank
hard

Fill both blanks to create a test group named 'Math tests' with a test inside it.

Flutter
group('[1]', () {
  test('[2]', () {
    expect(2 * 2, 4);
  });
});
Drag options to blanks, or click blank then click option'
AMath tests
BMultiplication test
CAddition test
DMath group
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated group or test names.
Omitting the group or test description.
5fill in blank
hard

Fill all three blanks to write a test that checks if a function 'add' returns 7 when adding 3 and 4.

Flutter
int [1](int a, int b) {
  return a + b;
}

test('[2]', () {
  expect([3](3, 4), 7);
});
Drag options to blanks, or click blank then click option'
Aadd
Badd function test
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching function names in definition and call.
Using incorrect test description.