Making your test a KoinComponent with KoinTest
koin_test.dart, you will be able to use all available test methods:
get()- function to retrieve yoru instances from Koin
testKoinDeclaration()- help you check your configuration. These are functions marked as isTest, that is, they are equivalent to test();
declareModule()- to declare a module to be loaded in the global context of koin
declare()- to a instance to be loaded in the global context of koin
koinTearDown()- Register a tearDown function that close Koin afters tests, will be called after each test is run.
koinSetUp()- Register a setUp function that starts koin before tests, will be called after each test is run.
koinTest()- Configures the testing environment to automatically start and close Koin for each test.
Don't hesitate to overload Koin modules configuration to help you partly build your app.
Create a Koin context for your test
You can easily create and hold a Koin context for each of your test with the following setup:
koin_test package does not have mockito as a dependency.
Mocking out of the box
Instead of making a new module each time you need a mock, you can declare a mock on the fly with
Checking your Koin modules
Koin offers a way to test if you Koin modules are good:
testModules - walk through your definition tree and check if each definition is bound
Starting & stopping Koin for your tests
Take attention to stop your koin instance (if you use
startKoin in your tests) between every test. Else be sure to use
koinApplication, for local koin instances or
stopKoin() to stop the current global instance.