当我运行我的测试时,显示以下错误
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 {
我在Android Studio 2.3.2上使用Roboelectric 3.3.2 快速帮助将受到高度赞赏!
答案 0 :(得分:6)
问题似乎在于包含多个模块的Android Studio项目。有两种解决方案:
从命令行运行Robolectric测试:
gradlew :app:testDebugUnitTest
从Android Studio运行Robolectric测试:
打开“编辑运行配置”对话框。在默认值>下Android JUnit,将工作目录设置为包含您正在测试的模块的文件夹。您可能还需要为每个现有的运行配置设置此选项。如果您在多个模块中进行了测试,则需要将每个运行配置的工作目录设置为适当的模块。