Check if using `UiAutomation.grantRuntimePermission()` instead of rule fixes tests

This commit is contained in:
Jorge Martín 2022-09-20 11:01:03 +02:00
parent 8624199be3
commit db562b99f8
2 changed files with 25 additions and 24 deletions

View File

@ -71,7 +71,7 @@ jobs:
force-avd-creation: false force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true disable-animations: true
# emulator-build: 7425822 emulator-build: 7425822
script: | script: |
./gradlew gatherGplayDebugStringTemplates $CI_GRADLE_ARG_PROPERTIES ./gradlew gatherGplayDebugStringTemplates $CI_GRADLE_ARG_PROPERTIES
./gradlew unitTestsWithCoverage $CI_GRADLE_ARG_PROPERTIES ./gradlew unitTestsWithCoverage $CI_GRADLE_ARG_PROPERTIES

View File

@ -18,7 +18,6 @@ package im.vector.app.features.voice
import android.Manifest import android.Manifest
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import io.mockk.spyk import io.mockk.spyk
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
@ -26,18 +25,20 @@ import org.amshove.kluent.shouldBeNull
import org.amshove.kluent.shouldExist import org.amshove.kluent.shouldExist
import org.amshove.kluent.shouldNotBeNull import org.amshove.kluent.shouldNotBeNull
import org.amshove.kluent.shouldNotExist import org.amshove.kluent.shouldNotExist
import org.junit.Rule import org.junit.Before
import org.junit.Test import org.junit.Test
import java.io.File import java.io.File
class VoiceRecorderLTests { class VoiceRecorderLTests {
@get:Rule
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.RECORD_AUDIO)
private val context = InstrumentationRegistry.getInstrumentation().targetContext private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val recorder = spyk(VoiceRecorderL(context, Dispatchers.IO)) private val recorder = spyk(VoiceRecorderL(context, Dispatchers.IO))
@Before
fun setup() {
InstrumentationRegistry.getInstrumentation().uiAutomation.grantRuntimePermission(context.packageName, Manifest.permission.RECORD_AUDIO)
}
@Test @Test
fun startRecordCreatesOggFile() = with(recorder) { fun startRecordCreatesOggFile() = with(recorder) {
getVoiceMessageFile().shouldBeNull() getVoiceMessageFile().shouldBeNull()