当我运行我的测试时,显示以下错误
No such manifest file: build\intermediates\bundles\debug\AndroidManifest.xml
java.lang.ClassCastException: android.app.Application cannot be cast to gyg.android.reviews.ReviewApplication
以下是Gradle依赖
compile group: 'org.mockito', name: 'mockito-all', version: '2.0.2-beta'
testCompile "org.robolectric:robolectric:3.3.2"
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'junit:junit:4.12'
这就是我开始测试课的方式
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class ReviewListPresenterTest {
我正在使用 Roboelectric 3.3.2 和 Android Studio 2.3.2 快速帮助将不胜感激!
最佳答案
问题似乎出在包含多个模块的 Android Studio 项目上。有两种解决方案:
从命令行运行 Robolectric 测试:
gradlew :app:testDebugUnitTest
从 Android Studio 运行 Robolectric 测试:
打开“编辑运行配置”对话框。在 Defaults > Android JUnit 下,将工作目录设置为包含您正在测试的模块的文件夹。您可能还需要为每个现有的运行配置设置此选项。如果您在多个模块中进行测试,则需要将每个运行配置的工作目录设置为适当的模块。
关于Android 单元测试 Robolectric :3. 3.2 - 没有这样的 list 文件 : build\intermediates\manifests\full\debug\src\main\AndroidManifest. xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43971063/