Setting up Unit Testing in AndroidStudio - 1.5 with Robolectric

AndroidStudio Version: 1.5 - Preview2
Robolectric: robolectric:3.0-rc2

  • Choose "Unit Tests" in "Build Variants" as "Test Artifact". 
  • Create a Unit Test under "src/test" folder.
  • Run the test !

Configuration details:

build.gradle additions related with unit tests:

dependencies {
    testCompile 'junit:junit:4.12'    testCompile('org.robolectric:robolectric:3.0-rc2') {
        exclude group: 'commons-logging', module: 'commons-logging'        exclude group: 'org.apache.httpcomponents', module: 'httpclient'    }

Sample Test class:
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

@Config(constants = BuildConfig.class, emulateSdk = 21)
public class MyTest {

    @Before    public void setUp() throws Exception {
        // setup    }

    @Test    public void testSomething() throws Exception {
        // test        assert(true);

No comments:

Post a Comment

Scheduling Repeating Local Notifications using Alarm Manager

Learn about Scheduling Repeating Local Notifications using Alarm Manager in this post .