Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robolectric @Config path value for manifest

Tags:

robolectric

I am trying to run robolectric unit test but I am getting error as AndroidManifest.xml not found on path. Can anyone give me an example path of @Config manifest value. Is it relative path or absolute one?

Thanks in advance

like image 211
Sunil Avatar asked Jul 03 '13 07:07

Sunil


People also ask

How to test robolectric framework?

Robolectric is not an integration test framework, i.e., you cannot not test the interaction of Android components with it. Robolectric does not require additional mocking frameworks, of course it is still possible to use frameworks like Mockito if desired. 1.2. Shadow objects Robolectric replaced all Android classes by so-called shadow objects .

What is robolectric?

Robolectric provides implementations of the Android SDK by rewriting the Android core libraries using shadow classes. This gives us the ability to execute our tests on the JVM and achieve much faster test execution times than if we were running on a device or emulator. in the Project Window.

How do I run robolectric tests on the JVM?

Your tests should be stored in the src/test directory. The class containing your Robolectric test must be annotate with the @RunWith (RobolectricGradleTestRunner.class) test runner. It must also use the @Config () to point to your BuildConfig.class class. The following shows an example test configured to run via Robolectric on the JVM.

How to create robolectric activity in Android?

Create an application called com.vogella.android.robolectric with an activity call RobolectricActivity . Use the com.vogella.android.robolectric top level package name.


1 Answers

If you are using maven to run your tests you can set as follows:

@Config(manifest = "../app/AndroidManifest.xml")
@RunWith(RobolectricTestRunner.class)
public class SomeTestCase { ... }

Please note that if you are using Android Studio/Intellij and want to run your tests within the IDE you will have to make a change in the Run configuration.

In Run->Edit configuration->Defaults->JUnit->Working directory set the value $MODULE_DIR$ and Android Studio will set the relative path in all junits just like Maven.

This worked for me however if the annotation fails, you can also create a file called "org.robolectric.Config.properties" and place it on your classpath.
The file should contain something like the following: "manifest: ./app/AndroidManifest.xml"

More information can be found here: Configuring Robolectric 2.0
A simple configuration using maven can be found here: Simple Robolectric

like image 100
Marco RS Avatar answered Oct 26 '22 17:10

Marco RS