Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidStudio/Gradle with powermock

I couldn't find any info on how to setup powermock with Android Studio/Gradle. Everything I've tried resulted in build exceptions.

Could anybody show a correct way to do it?

Thanks.

like image 932
midnight Avatar asked Aug 05 '14 10:08

midnight


3 Answers

I'm posting in order to help future readers, you need to add these dependencies for powermock in AS

testImplementation 'junit:junit:4.12'
testImplementation 'org.powermock:powermock-api-mockito:1.6.2'
testImplementation 'org.powermock:powermock-module-junit4-rule-agent:1.6.2'
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.2'
testImplementation 'org.powermock:powermock-module-junit4:1.6.2'
like image 78
Bhargav Avatar answered Nov 03 '22 09:11

Bhargav


Add the following lines to your dependencies{} block:

testCompile 'junit:junit:4.12'
testCompile 'org.powermock:powermock:1.6.5'
testCompile 'org.powermock:powermock-module-junit4:1.6.5'

And if you would like to use PowerMockito, add the following line:

testCompile 'org.powermock:powermock-api-mockito:1.6.5'
like image 25
plátano plomo Avatar answered Nov 03 '22 08:11

plátano plomo


In the build script, add the following:

sourceSets {
    unitTest {
        java.srcDir file('*your test directory*') //for example: tests/java
    }
}

android {
    sourceSets {
        instrumentTest.setRoot('*your root test directory*') //for example: tests
    }
}

repositories {
    mavenCentral()
}

dependencies {
    testCompile 'junit:junit:4.11'
    testCompile 'org.powermock:powermock-mockito-release-full:1.4.9'
}

Then, do gradle unitTest from the command line.

Hope that works. If it doesn't, post the output of the command line.

like image 5
sasfour Avatar answered Nov 03 '22 10:11

sasfour