text
stringlengths
1
372
tracked by code coverage, plus enough integration tests
to cover all the important use cases. this advice is based on
the fact that there are trade-offs between different kinds of testing,
seen below.
<topic_end>
<topic_start>
unit tests
a unit test tests a single function, method, or class.
the goal of a unit test is to verify the correctness of a
unit of logic under a variety of conditions.
external dependencies of the unit under test are generally
mocked out.
unit tests generally don’t read from or write
to disk, render to screen, or receive user actions from
outside the process running the test.
for more information regarding unit tests,
you can view the following recipes
or run flutter test --help in your terminal.
info note
if you’re writing unit tests for code that
uses plugins and you want to avoid crashes,
check out plugins in flutter tests.
if you want to test your flutter plugin,
check out testing plugins.
<topic_end>
<topic_start>
recipes
an introduction to unit testing
mock dependencies using mockito
<topic_end>
<topic_start>
widget tests
a widget test (in other UI frameworks referred to as component test)
tests a single widget. the goal of a widget test is to verify that the
widget’s UI looks and interacts as expected. testing a widget involves
multiple classes and requires a test environment that provides the
appropriate widget lifecycle context.
for example, the widget being tested should be able to receive and
respond to user actions and events, perform layout, and instantiate child
widgets. a widget test is therefore more comprehensive than a unit test.
however, like a unit test, a widget test’s environment is replaced with
an implementation much simpler than a full-blown UI system.
<topic_end>
<topic_start>
recipes
an introduction to widget testing
find widgets
handle scrolling
tap, drag, and enter text
<topic_end>
<topic_start>
integration tests
an integration test tests a complete app or a large part of an app.
the goal of an integration test is to verify that all the widgets
and services being tested work together as expected.
furthermore, you can use integration
tests to verify your app’s performance.
generally, an integration test runs on a real device or an OS emulator,
such as iOS simulator or android emulator.
the app under test is typically isolated
from the test driver code to avoid skewing the results.
for more information on how to write integration tests, see the integration
testing page.
<topic_end>
<topic_start>
recipes
an introduction to integration testing
performance profiling
<topic_end>
<topic_start>
continuous integration services
continuous integration (ci) services allow you to run your
tests automatically when pushing new code changes.
this provides timely feedback on whether the code
changes work as expected and do not introduce bugs.
for information on running tests on various continuous
integration services, see the following:
<topic_end>
<topic_start>
an introduction to unit testing
how can you ensure that your app continues to work as you
add more features or change existing functionality?
by writing tests.
unit tests are handy for verifying the behavior of a single function,
method, or class. the test package provides the
core framework for writing unit tests, and the flutter_test
package provides additional utilities for testing widgets.
this recipe demonstrates the core features provided by the test package
using the following steps:
for more information about the test package,
see the test package documentation.
<topic_end>
<topic_start>
1. add the test dependency
the test package provides the core functionality for
writing tests in dart. this is the best approach when
writing packages consumed by web, server, and flutter apps.
to add the test package as a dev dependency,
run flutter pub add:
<topic_end>