Mockito generates mocks for all classes listet within the @GenerateMocks annotatio. It does so for tests in the test folder but it doesn't for tests in the integration_test folder. How do I change that?
Is there a way to let mockito generate mocks for integration tests in a Flutter project
2.3k Views Asked by HerrJohr At
2
There are 2 best solutions below
0
On
To extend on HerrJohr's answer:
targets:
$default:
sources:
include:
- $package$
- lib/$lib$
- lib/**
- test/**
- integration_test/**
builders:
mockito|mockBuilder:
generate_for:
include:
- test/**
- integration_test/**
See more:
- Default
sources- build/build_runner_core/lib/src/generate /options.dart - "How can I include additional sources in my build?" from build/docs/faq.md
- Default
generate_for- mockito/build.yaml
TL;DR
Add a build.yaml file with the following content to your project root folder.
Explanation
Both
generate_forandsourcesare needed to tell the mockBuilder which files should be processed.The
generate_forconfiguration is only a subset of the all the files used by the builder. But these files do not include the integration_test folder by default. To modify that, we can list the sources files manually. We have to include the default sources$package$andlib/$lib$, or we will get warnings if not.By including any folder - in our case 'integration_test' it will then also be available to
generate_for.Here is the excerpt from the build_config/README.md:
sourceswhich should have this Builder applied. Seesourcesconfiguration above for how to configure this.and:
includeandexclude. Any file which matches any glob inincludeand no globs inexcludeis considered a source of the target. Whenincludeis omitted every file is considered a match.