I am developing an Android project on Eclipse, and I\'m trying to switch from running tests on the emulator/device (which is very slow) to Robolectric.
I re
We have had the same problems in the past. What works for us is extending RoboletricTestRunner and providing it a RoboletricConfig instance that is aware of our Project's location. This way I don't have to tinker with any run configurations with eclipse, it just works.
package ...;
import java.io.File;
import org.junit.runners.model.InitializationError;
import com.xtremelabs.robolectric.RobolectricConfig;
import com.xtremelabs.robolectric.RobolectricTestRunner;
public class TestRunner extends RobolectricTestRunner {
public static final string MAIN_PROJECT_PATH = "../path_to_android_project";
public TestRunner(Class<?> testClass) throws InitializationError {
super(testClass, new RobolectricConfig(new File(MAIN_PROJECT_PATH)));
}
}
Normally you won't need to extend TestCase, but I don't think that should be causing this problem. Could you include the source of the failing test?
Regarding the simplified project in your update, make sure that Eclipse is configured to set the current working directory to the root of the main project, not the test project, so it will find AndroidManifest.xml and the res directory.
No need to create a custom RoboelectricTestRunner, just play a bit with your 'Run Configurations' on Eclipse. On the configuration for running your tests, go to the classpath tab and ensure that the libraries required for your test, e.g. robolectric-2.2-jar-with-dependencies.jar and android.jar and the project itself are in the User Entries and ONLY the Java SDK is in the Bootstrap Entries.
Then add this file:
[project_path]/test/org.robolectric.Config.properties
manifest=../AndroidManifest.xml