Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flutter test package.
Flutter
import 'package:flutter_test/[1]';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding '.dart' extension in the import path.
Using 'test' package instead of 'flutter_test'.
✗ Incorrect
The correct import for Flutter's testing package is 'flutter_test' without any file extension.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different test description string.
Omitting the test description.
✗ Incorrect
The test description should be 'adds two numbers' as specified.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using matcher functions like equals(5) which are not needed here.
Passing a string instead of a number.
✗ Incorrect
The expect function compares the actual value to the expected value directly, so just use 5.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated group or test names.
Omitting the group or test description.
✗ Incorrect
The group name is 'Math tests' and the test description is 'Multiplication test' as required.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching function names in definition and call.
Using incorrect test description.
✗ Incorrect
The function name is 'add', the test description is 'add function test', and the function call is 'add(3, 4)'.