Where to specify Android Instumentation test data

I want to use large files (> 2 GB of zip archives as well as video files) in my instrumental tests to verify file downloads from an SD card / internal storage.

How can I write these control tests and equip them with the files they need? For other tests, I needed very small files, so I put them in the source resources of the application

InputStream rStream = context.getResources().openRawResource(R.raw.smalltestvideo);

But now I need to specifically test large files, for which this is no longer an option. I am running with

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+4
source share
2 answers

script, build.gradle .

, @m-reza-nasirloo , , CI . script .

: script ,  ( testFiles) , . .

, script . , Android Studio, , , .

, script Android, gradle assembleDebugAndroidTest . , if, .

import com.android.ddmlib.AndroidDebugBridge

task pushFilesToDevices {
    def location = "${project.rootDir}/../testFiles/"
    def files = new File(location).listFiles()
    AndroidDebugBridge.initIfNeeded(false)
    def bridge = AndroidDebugBridge.createBridge(android.adbExecutable.path, false)
    doLast {
        bridge.devices.each { device ->
            println "pushing files to ${device.name}"
            files.each { file ->
                device.pushFile(file.absolutePath, "/sdcard/${file.name}")
            }
            println "finished pushing"
        }
    }
}

tasks.whenTaskAdded { taskItem ->
    if (taskItem.name.contains("assemble") && taskItem.name.endsWith("AndroidTest")) {
        taskItem.dependsOn pushFilesToDevices
    }
}
+4

Test Assets - Assets . , ( ).

: src/androidTest/assets

gradle:

androidTest {
    assets.srcDirs = ['src/main/assets', 'src/androidTest/assets/']
    java.srcDirs = ['src/main/java', 'src/androidTest/java'] //you probably already have this
}
0

Source: https://habr.com/ru/post/1694676/


All Articles