Kotlin + Mockito2:演示者测试的ClassNotFoundException

我有一个基于CleanArchitecture-Android风格的Kotlin编写的示例应用程序。 以下是应用程序的配置:

演示/的build.gradle

dependencies { implementation project(':domain') def presentationDependencies = rootProject.ext.presentationDependencies def commonDependencies = rootProject.ext.commonDependencies testCompile testingDependencies.junit testCompile testingDependencies.mockito // org.mockito:mockito-inline:2.10.0 } 

呈现/ SRC /测试/ JAVA /包/ RepoPreferencesPresenterTest.kt

 internal class RepoPreferencesPresenterTest : UnitTest() { // FIXME: Mocking fails @Mock private lateinit var mockRepositoriesUseCase: RepositoriesUseCase @Mock private lateinit var mockView: RepoPreferencesContract.View private lateinit var presenter: RepoPreferencesPresenter<RepoPreferencesContract.View> @Before fun setUp() { presenter = RepoPreferencesPresenter(mockRepositoriesUseCase) presenter.onAttach(mockView) } } 

当我尝试运行测试用例时,每次遇到ClassNotFoundException 。 无法模拟演示者测试的域模块中存在的UseCase,除了该应用程序运行良好。

 java.lang.NoClassDefFoundError: Lcom/sample/domain/usecases/RepositoriesUseCase; ...... Caused by: java.lang.ClassNotFoundException: com.sample.domain.usecases.RepositoriesUseCase at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 

任何想法如何解决这个问题? (我也试过使用模拟器内联,但它不工作)

通过手动指定presentation/build.gradle所有模块的类路径来解决此问题

 sourceSets { main.java.srcDirs += 'src/main/java' main.java.srcDirs += [file("$buildDir/generated/source/kapt/main")] main.java.srcDirs += '../data/src/main/java' main.java.srcDirs += '../entities/src/main/java' main.java.srcDirs += '../domain/src/main/java' } 

设置 :Android Studio 3.0-Beta 6的Gradle版本“3.0.0-beta6”。