Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manifest and setup issues getting Robolectric working with Android Studio 1.1.0

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.1.0+. This is my project structure:

enter image description here

and here is my test:

import android.widget.Button;

import com.mycompany.android.app.R;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import static org.junit.Assert.assertNotNull;

@Config(manifest = "AndroidManifest.xml")
@RunWith(RobolectricTestRunner.class)
public class SplashActivityTest {

    private SplashActivity splashActivity;

    @Before
    public void setup() {
        splashActivity = Robolectric.buildActivity(SplashActivity.class).create().start().resume().get();
    }

    @Test
    public void shouldNotBeNull() {
        Button signUpButton = (Button) splashActivity.findViewById(R.id.sign_up_button);
        assertNotNull(signUpButton);

        Button loginButton = (Button) splashActivity.findViewById(R.id.login_button);
        assertNotNull(loginButton);
    }

}

No matter what I do to try and get the framework to find the test by changing the path to the manifest, it cannot find it - either I get 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! messages. In the end, I think this is the reason I'm getting the following errors when the test runs:

android.content.res.Resources$NotFoundException: unknown resource 2130903074

I do have the experimental option turned on, have the right Gradle plugin configured (unit tests work fine), but I'm not sure what I'm missing to get instrumentation tests up and running.

App-level build file:

apply plugin: 'org.robolectric'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.hamcrest:hamcrest-core:1.1'
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile 'org.hamcrest:hamcrest-integration:1.1'

Top-level build file:

dependencies {
    classpath 'com.android.tools.build:gradle:1.1.0'
    classpath 'org.robolectric:robolectric-gradle-plugin:1.0.0'
}
like image 684
TheIcemanCometh Avatar asked Feb 24 '15 15:02

TheIcemanCometh


People also ask

What is the manifest file for Android app?

For an introduction to the app manifest file, see the app manifest overview. Your APK or Android App Bundle file can contain just one AndroidManifest.xml file, but your Android Studio project may contain several—provided by the main source set, build variants, and imported libraries.

Which Android Studio files should be excluded from real-time scanning?

The following list shows the default location of each Android Studio directory that you should exclude from real-time scanning: Gradle cache %USERPROFILE%.gradle Android Studio projects %USERPROFILE%AndroidStudioProjects Android SDK %USERPROFILE%AppDataLocalAndroidSDK. Android Studio system files. Syntax: %LOCALAPPDATA%Google<product><version>

Why is my Android Studio build taking so long?

Some antivirus software can interfere with the Android Studio build process, causing builds to run dramatically slower. When you run a build in Android Studio, Gradle compiles your app’s resources and source code and then packages the compiled resources together in an APK. During this process, many files are created on your computer.

How to build Android app with embedded JDK?

1 Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle ( Android Studio > Preferences ... 2 Under Gradle JDK, choose the Embedded JDK option. 3 Click OK.


1 Answers

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

like image 83
nenick Avatar answered Sep 28 '22 00:09

nenick