1

This is my Activity where my AppModule Test activity is calling Another module's dependency.

class MyPageActivityTest {

    lateinit var myPageActivity: MyPageActivity
    @RelaxedMockK
    lateinit var context: Context
    lateinit var mBTest: BComponentTest
    lateinit var mATest: AComponentTest
    @Before
    fun setUp() {
        MockKAnnotations.init(this,true)


        mBTest = DaggerBComponentTest.builder()
            .buildBModule(BModuleTest(context)).build()

         mATest= DaggerAComponentTest
             .builder()
             .buildAppModule(AModuleTest(context))
             .buildBTestComponent(mBTest)
             .build()

        myPageActivity =
            Robolectric.buildActivity(MyPageActivity::class.java)
                .create()
                .resume()
                .get()
    }

    @Test
    fun test(){
        myPageActivity.onBackPressed()
    }
}

Here is my Bcomponent:

@Component(modules = [BModuleTest::class])
interface BComponentTest {

    @Component.Builder
    interface Builder {
        fun buildBModule(bModule: BModuleTest): Builder

        @BindsInstance
        fun build(): BComponentTest
    }
}

Now, here is my App module's test dependency component which is having other modules, here BComponentTest, as dependency of test module.

@Component(modules = [AppModuleTest::class],dependencies = [BComponentTest::class] )
interface AComponentTest  {
    @Component.Builder
    interface Builder {
        fun buildBTestComponent(mBComponent: BComponentTest):Builder
        fun buildAppModule(appModule: AppModuleTest): Builder
        fun build(): AComponentTest
    }
}

I am getting error when I am running test of same activity.


error: cannot find symbol @dagger.Component(modules = {com.x.x.di.modules.AppModuleTest.class}, dependencies = {BComponentTest.class})
                                                                                                             ^   symbol: class AComponentTest

AND

error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public abstract interface AComponentTest {

Every other testcases are working fine but when it comes to building 'testing dagger of Base to Dependent module', it is not working.

Any one can suggest where i am wrong.

Reshma
  • 1,449
  • 2
  • 10
  • 17

0 Answers0