Manifest and setup issues getting Robolectric working with Android Studio 1.1.0

前端 未结 6 1638
盖世英雄少女心
盖世英雄少女心 2021-01-18 07:29

I am trying to get Robolectric tests up and working in our current project, and not having a lot of luck. My preference would be to get these to run within Android Studio 1

6条回答
  •  独厮守ぢ
    2021-01-18 08:30

    I have faced same errors. We use several flavors and buildtypes So, there are steps to make it working:

    1) Android studio tests run configuration

    Build Variants menu

    You have to set working directory to $MODULE_DIR$ in Windows too. robolectric.org/getting-started/ should say that.

    Run Configuration Menu

    2) Unit test should be annotated like this:

    @RunWith(RobolectricTestRunner.class) 
    @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml", packageName = "com.example.yourproject") 
    public class SomeFragmentTest {
    

    Here we have plain link to manifest file and packageName

提交回复
热议问题