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
After few days struggling, I eventually figured out the root cause of your question:
WARNING: No manifest file found at ./AndroidManifest.xml.Falling back to the Android OS resources only. messages, or API Level XX is not supported - Sorry!
Many answers I found on stackOverFlow told me to add the path of Manifest file to the @Config like this:
@Config(manifest = "src/main/AndroidManifest.xml")
It did work for one of my projects, but when I opened a new project and set up the testing environment, same error message popped up.
The reason behind this would be the different working directory of your project. You should locate your working directory first, and then specify the relative path to it in your @Config(maniest = "...").
Where can I find Working directory in Android Studio?
Run -> Edit Configurations -> Junit -> Your Test
-> Configuration Tab -> **Working directory:**
Take my working directory as an example, my working directory is
"/Users/Bible/AndroidstudioProjects/MVP"
so the path to my AndroidManifest.xml should be
@Config(manifest = "app/src/main/AndroidManifest.xml")
Here you go! Hope this answer can make your life easier.
If you are using latest Android Studio(1.2.x), then its better too use RobolectricGradleTestRunner.class It's designed for different build flavors and test flavors. You also need not specify your source manifest. It will pickup the manifest based on your build flavor you are running. This is specially useful when you have different build environments(staging, production) and you want to run your test cases in a specific environment
I wrote a step by step guide how to enable robolectric with android studio 1.1.0 http://nenick-android.blogspot.de/2015/02/android-studio-110-beta-4-and.html I guess you will find an answer for your issue. And an example https://github.com/nenick/AndroidStudioAndRobolectric
In your case next change might help:
@Config(manifest = "src/main/AndroidManifest.xml", emulateSdk = 18, reportSdk = 18)
But read also @nenick guide
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
You have to set working directory to $MODULE_DIR$ in Windows too. robolectric.org/getting-started/ should say that.
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
I just changed to:
@RunWith(RobolectricTestRunner.class)
and it works. All the other config stuff seems to be unnecessary.