Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso testing in separate module

I have the android application and I want to use Espresso framework to create test automation tools and tests. But I don't want to create something in my app and want separate module with Espresso that will start my app and test it using Espresso. I use Android Studio. So.. Have you any ideas how to solve this problem?

like image 535
Franciscosuarez Avatar asked Mar 17 '26 23:03

Franciscosuarez


1 Answers

You can use a library module specialised for instrumentation tests. Basically just create a library module but use a different plugin:

apply plugin: 'com.android.test' // A plugin used for test-only-modules 

Also you need to changep your android part in your build.gradle file in your test module a little:

android {
    [...]

    defaultConfig {
        [...]
        testApplicationId "com.yourcompany.yourapp.test"
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }

    [...]

    // Set the target app project.
    // The module specified here should contain the
    // production code test should run against.
    targetProjectPath ':app'
}

Then add your app and all your espresso libraries etc. in your test module's dependencies:

dependencies {
    implementation project(':app')

    // All your test dependencies etc.
    implementation "androidx.test.espresso:espresso-core:$espresso_version"
}

Using a gradle sync and run tests you can then execute your tests locally. You'll also get all your normal gradle tasks for that module which you can use to assemble your test APK etc. if you need it to test externally e.g. in Firebase Test Labs.

like image 140
Oliver Metz Avatar answered Mar 20 '26 12:03

Oliver Metz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!