Run Android Instrumentation Tests as part of PR workflow (#2309)

This commit is contained in:
Bart Louwers
2024-04-22 22:47:22 +02:00
committed by GitHub
parent d5775d374b
commit 8ad141e213
6 changed files with 55 additions and 110 deletions

View File

@@ -146,7 +146,7 @@ class BenchmarkActivity : AppCompatActivity() {
private fun getBenchmarkInputData(): BenchmarkInputData {
// read input for benchmark from JSON file (on CI)
val jsonFile = File("${Environment.getExternalStorageDirectory()}/benchmark-input.json")
val jsonFile = File("${Environment.getExternalStorageDirectory()}/instrumentation-test-input")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && Environment.isExternalStorageManager() && jsonFile.isFile) {
val jsonFileContents = jsonFile.readText()
val jsonElement = Json.parseToJsonElement(jsonFileContents)
@@ -192,7 +192,7 @@ class BenchmarkActivity : AppCompatActivity() {
handler = Handler(mainLooper)
setupToolbar()
inputData = getBenchmarkInputData()
setupMapView(savedInstanceState)
setupMapView()
}
private fun setupToolbar() {
@@ -203,10 +203,10 @@ class BenchmarkActivity : AppCompatActivity() {
}
}
private fun setupMapView(savedInstanceState: Bundle?) {
private fun setupMapView() {
mapView = findViewById<View>(R.id.mapView) as MapView
if (measureFrameTime) {
mapView.addOnDidFinishRenderingFrameListener { fully: Boolean, frameEncodingTime: Double, frameRenderingTime: Double ->
mapView.addOnDidFinishRenderingFrameListener { _: Boolean, frameEncodingTime: Double, frameRenderingTime: Double ->
encodingTimeStore.add(frameEncodingTime * 1e3)
renderingTimeStore.add(frameRenderingTime * 1e3)
}

View File

@@ -1,8 +1,25 @@
package org.maplibre.android.testapp.utils
import android.content.Context
import android.os.Build
import android.os.Environment
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.contentOrNull
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.maplibre.android.MapLibre
import java.lang.Exception
import java.io.File
fun readFromJSON(): String? {
val jsonFile = File("${Environment.getExternalStorageDirectory()}/instrumentation-test-input.json")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && Environment.isExternalStorageManager() && jsonFile.isFile) {
val jsonFileContents = jsonFile.readText()
val jsonElement = Json.parseToJsonElement(jsonFileContents)
return jsonElement.jsonObject["apiKey"]?.jsonPrimitive?.contentOrNull
}
return null
}
object ApiKeyUtils {
/**
@@ -18,6 +35,10 @@ object ApiKeyUtils {
* @return The api key or null if not found.
*/
fun getApiKey(context: Context): String? {
val fromJSON = readFromJSON()
if (fromJSON !== null) return fromJSON
return try {
// Read out AndroidManifest
val apiKey = MapLibre.getApiKey()