Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write persistent file to /sdcard/googletest/test_outputfiles
Browse files Browse the repository at this point in the history
bartekpacia committed Sep 29, 2023
1 parent 6675830 commit f879189
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,56 @@
package pl.leancode.patrol

import android.annotation.SuppressLint
import android.os.Build
import android.os.Bundle
import androidx.annotation.OptIn
import androidx.test.annotation.ExperimentalTestApi
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.services.storage.TestStorage
import org.junit.runner.*
import org.junit.runner.notification.*
import java.io.FileNotFoundException
import org.junit.runner.Description
import org.junit.runner.notification.RunListener

@OptIn(ExperimentalTestApi::class)
class CustomPatrolJUnitRunner : PatrolJUnitRunner() {
private var testStorage: TestStorage? = null

override fun onCreate(arguments: Bundle) {
super.onCreate(arguments)
testStorage = TestStorage()
try {
testStorage!!.openOutputFile("patrol_state/teardowns.txt")
} catch (e: FileNotFoundException) {
throw RuntimeException(e)
}

val listeners = listOf(
// try {
// val outputStream = testStorage!!.openOutputFile("patrol_state/teardowns.txt")
// } catch (e: FileNotFoundException) {
// throw RuntimeException(e)
// }

val listeners = listOfNotNull(
arguments.getCharSequence("listener"),
PatrolStoragePermissionListener::class.java.name,
).joinToString(separator = ",")

arguments.putCharSequence("listener", listeners)
super.onCreate(arguments)
}

override fun onStart() {
super.onStart()

testStorage = TestStorage()
}
}

@SuppressLint("UnsafeOptInUsageError")
class PatrolStoragePermissionListener : RunListener() {
@Throws(Exception::class)
override fun testRunStarted(description: Description) {

val testStorage by lazy { TestStorage() }

override fun testStarted(description: Description) {
Logger.d("testStarted with description: $description")


val os = testStorage.openOutputFile("patrol.txt", true)
os.write("testStarted with description: $description\n".toByteArray())


InstrumentationRegistry.getInstrumentation().uiAutomation.apply {
val testServicesPackage = "androidx.test.services"
when {
2 changes: 1 addition & 1 deletion packages/patrol/example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ android {
targetSdk 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner"
testInstrumentationRunner "pl.leancode.patrol.CustomPatrolJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: "true"
}

0 comments on commit f879189

Please sign in to comment.