Flutter › Unit Testing in Flutter

What is a unit test in Flutter, and how does the flutter_test package's own test function let you write and organize a genuinely simple basic test?

Beginner

Answer

A unit test verifies that one single small isolated piece of logic, such as a single function or a single class's own particular method, behaves genuinely exactly as expected when given a specific set of inputs, and the test function, provided directly by the flutter_test package, lets you properly define an individual named test containing your own actual test logic, typically calling the specific function or method genuinely under test and then properly asserting the resulting actual output correctly matches your own genuinely expected value.
test('add returns the correct sum', () {
  expect(add(2, 3), equals(5));
});
Real-world example A developer writes a genuinely simple unit test verifying that a calculateDiscount function correctly returns the exact expected discounted price for a given specific input price and discount percentage.

Common follow-ups: What genuinely does the expect function actually specifically do when a given test's own assertion genuinely fails?;How do you actually properly organize several genuinely related tests together using the group function?