Android unit testing issues with dagger2 and kotlin

后端 未结 1 417
孤城傲影
孤城傲影 2021-01-15 07:15

I am trying to create a dagger component interface in the test folder of android,but after Dagger is done with the generated class its show an error as \"Cannot access Test

相关标签:
1条回答
  • 2021-01-15 07:53

    I had the same problem here setting up my tests on our repo here. When seeing examples from Tivi, I noticed that our generated sources weren't being included to the source sets.

    Adding a gradle script somewhere in your project should fix your problem.

    Ex: https://github.com/toggl/android/blob/768f01b55c47ffd3bb7c4a82dea4abf50eac9e1c/database-android/build.gradle#L46-L63 (same as Tivi).

    main.java.srcDirs += 'src/main/kotlin'
    debug.java.srcDirs += 'src/debug/kotlin'
    release.java.srcDirs += 'src/release/kotlin'
    test.java.srcDirs += 'src/test/kotlin'
    
    // For kapt stubs
    main.java.srcDirs += [file("$buildDir/generated/source/kapt/main")]
    debug.java.srcDirs += [file("$buildDir/generated/source/kapt/debug")]
    release.java.srcDirs += [file("$buildDir/generated/source/kapt/release")]
    test.java.srcDirs += [file("$buildDir/generated/source/kapt/test")]
    
    // For kotlin code gen during kapt
    main.java.srcDirs += [file("$buildDir/generated/source/kaptKotlin/main")]
    debug.java.srcDirs += [file("$buildDir/generated/source/kaptKotlin/debug")]
    release.java.srcDirs += [file("$buildDir/generated/source/kaptKotlin/release")]
    test.java.srcDirs += [file("$buildDir/generated/source/kaptKotlin/test")]
    
    0 讨论(0)
提交回复
热议问题