Component - Unit testing
This UI component shows a simple Flutter widget with a button and a text label. The button increments a counter when pressed. Unit testing checks the logic that updates the counter without running the full app UI.
This UI component shows a simple Flutter widget with a button and a text label. The button increments a counter when pressed. Unit testing checks the logic that updates the counter without running the full app UI.
Scaffold
├─ AppBar
│ └─ Text
└─ Center
└─ Column
├─ Text
└─ ElevatedButton
└─ TextWhat is the main purpose of unit testing in Flutter?
Which of the following is the correct syntax to write a simple test in Flutter?
?What will be the output of this test code?
int add(int a, int b) => a + b;
test('add function test', () {
expect(add(2, 3), 5);
expect(add(0, 0), 0);
expect(add(-1, 1), 0);
});Choose the correct test result.
Identify the error in this Flutter unit test code:
test('string length test', () {
var str = 'hello';
expect(str.length, '5');
});You want to test a function that returns a list of even numbers from a given list. Which test code correctly verifies this behavior?
List<int> filterEven(List<int> nums) => nums.where((n) => n % 2 == 0).toList();
// Which test is correct?Pass the test and this pattern moves unknown