Questions tagged [daggermock]

A JUnit rule to easily override Dagger 2 objects.

Overriding an object managed by Dagger 2 is not easy, you need to define a TestModule and, if you want to inject your test object, a TestComponent.

Using a DaggerMockRule it's possible to override easily the objects defined in a Dagger module

https://github.com/fabioCollini/DaggerMock

8 questions
10
votes
2 answers

Dagger 2 How to inject object into test

I would like to use my realm manager into unit test module. I did @Singleton @Component(modules = { TestApplicationModule.class, AndroidSupportInjectionModule.class, TestStoreDataModule.class, …
Piotr Badura
  • 1,574
  • 1
  • 13
  • 17
4
votes
1 answer

Unit testing with Dagger and AWS Lambda

I am trying to set up Dagger in my Serverless project which has a number of Java AWS Lambda implementations. The Lambda code is relatively straightforward and mostly deals with reading the request and writing the response, with service classes doing…
Stuart Leyland-Cole
  • 1,243
  • 7
  • 19
  • 35
3
votes
1 answer

DaggerMock - How to get dagger to provide object in a test case

I am doing a junit testing on a use case i have (MVP architecture if that matters) with dagger2. The problem is i would like to use Dagger2 injection inside of my junit test case sometimes. So i looked into DaggerMock library for this. I have…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
2
votes
0 answers

Dagger2 - how to switch to moked modules when testing

I am looking for the best approach to inject mock dependencies instead of real once in the tested classes while i am running unit/integration tests. I have two issues: 1. With application scoped dependencies 2. With activity scoped…
danidin
  • 371
  • 2
  • 17
1
vote
1 answer

MockK class verification breaking with Dagger

Overview Expected: Testing Dagger created repository class with empty constructor Issue: Mockk verification is breaking with mockkConstructor and confirmVerified using Dagger dependency injection to create a repository class. When implementing a…
AdamHurwitz
  • 9,758
  • 10
  • 72
  • 134
0
votes
1 answer

Dagger Parent Component scoping

If I use Core-component as parent component of my AppComponent , and the scope for the AppComponent is singleton. Is all the dependency derive from corecomponent would be singletone ? I mean Only one instance will be created for parent provided…
0
votes
1 answer

How to inject a MockModule into DaggerAppComponent?

I have been using Dagger Android for a while, and now I want to inject a MockModule for testing purposes, and I do not know how to get it. I have seen on some posts that they call something like: DaggerAppComponent.builder() …
Chiara
  • 1,867
  • 15
  • 17
0
votes
1 answer

Mock dependent component's dependency with DaggerMock

I want to write Espresso tests for an app so I'm trying DaggerMock to mock some external dependencies like local storage. My Dagger setup consists of an ApplicationComponent with 3 modules (DatabaseModule, DataModule and ApplicationModule) and for…
Mes
  • 1,671
  • 3
  • 20
  • 36