Try to fix tests, address review comments.

This commit is contained in:
Jorge Martín 2022-06-15 11:34:18 +02:00
parent 64334c3437
commit c204f41bec
4 changed files with 37 additions and 23 deletions

View File

@ -29,7 +29,7 @@ def jjwt = "0.11.5"
def vanniktechEmoji = "0.15.0" def vanniktechEmoji = "0.15.0"
// Testing // Testing
def mockk = "1.12.3" def mockk = "1.12.3" // We need to use 1.12.3 to have mocking in androidTest until a new version is released: https://github.com/mockk/mockk/issues/819
def espresso = "3.4.0" def espresso = "3.4.0"
def androidxTest = "1.4.0" def androidxTest = "1.4.0"
def androidxOrchestrator = "1.4.1" def androidxOrchestrator = "1.4.1"

View File

@ -337,7 +337,6 @@ android {
} }
dependencies { dependencies {
implementation fileTree(dir: "libs", include: ["*.aar", "*.jar"])
implementation project(':library:opusencoder') implementation project(':library:opusencoder')
implementation project(":vector-config") implementation project(":vector-config")

View File

@ -20,7 +20,6 @@ import android.Manifest
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule import androidx.test.rule.GrantPermissionRule
import io.mockk.spyk import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import org.amshove.kluent.shouldBeNull import org.amshove.kluent.shouldBeNull
import org.amshove.kluent.shouldExist import org.amshove.kluent.shouldExist
@ -60,14 +59,13 @@ class VoiceRecorderLTests {
} }
@Test @Test
fun cancelRecordRemovesFileAfterStopping() = with(recorder) { fun cancelRecordRemovesFile() = with(recorder) {
startRecord("some_room_id") startRecord("some_room_id")
val file = recorder.getVoiceMessageFile() val file = recorder.getVoiceMessageFile()
file.shouldNotBeNullAndExist() file.shouldNotBeNullAndExist()
cancelRecord() cancelRecord()
verify { stopRecord() }
getVoiceMessageFile().shouldBeNull() getVoiceMessageFile().shouldBeNull()
file!!.shouldNotExist() file!!.shouldNotExist()
} }

View File

@ -17,10 +17,14 @@
package im.vector.app.features.voice package im.vector.app.features.voice
import android.Manifest import android.Manifest
import android.os.Build
import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule import androidx.test.rule.GrantPermissionRule
import io.mockk.spyk import io.mockk.spyk
import io.mockk.verify import io.mockk.verify
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.amshove.kluent.shouldBeNull 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
@ -29,6 +33,7 @@ import org.junit.Rule
import org.junit.Test import org.junit.Test
import java.io.File import java.io.File
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.Q)
class VoiceRecorderQTests { class VoiceRecorderQTests {
@get:Rule @get:Rule
@ -38,38 +43,50 @@ class VoiceRecorderQTests {
private val recorder = spyk(VoiceRecorderQ(context)) private val recorder = spyk(VoiceRecorderQ(context))
@Test @Test
fun startRecordCreatesOggFile() = with(recorder) { fun startRecordCreatesOggFile() = runBlocking {
with(recorder) {
getVoiceMessageFile().shouldBeNull() getVoiceMessageFile().shouldBeNull()
startRecord("some_room_id") startRecord("some_room_id")
waitForRecording()
getVoiceMessageFile().shouldNotBeNullAndExist() getVoiceMessageFile().shouldNotBeNullAndExist()
stopRecord() stopRecord()
} }
}
@Test @Test
fun stopRecordKeepsFile() = with(recorder) { fun stopRecordKeepsFile() = runBlocking {
with(recorder) {
getVoiceMessageFile().shouldBeNull() getVoiceMessageFile().shouldBeNull()
startRecord("some_room_id") startRecord("some_room_id")
waitForRecording()
stopRecord() stopRecord()
getVoiceMessageFile().shouldNotBeNullAndExist() getVoiceMessageFile().shouldNotBeNullAndExist()
} }
}
@Test @Test
fun cancelRecordRemovesFileAfterStopping() = with(recorder) { fun cancelRecordRemovesFileAfterStopping() = runBlocking {
with(recorder) {
startRecord("some_room_id") startRecord("some_room_id")
val file = recorder.getVoiceMessageFile() val file = recorder.getVoiceMessageFile()
file.shouldNotBeNullAndExist() file.shouldNotBeNullAndExist()
waitForRecording()
cancelRecord() cancelRecord()
verify { stopRecord() } verify { stopRecord() }
getVoiceMessageFile().shouldBeNull() getVoiceMessageFile().shouldBeNull()
file!!.shouldNotExist() file!!.shouldNotExist()
} }
}
// Give MediaRecorder some time to actually start recording
private suspend fun waitForRecording() = delay(10)
} }
private fun File?.shouldNotBeNullAndExist() { private fun File?.shouldNotBeNullAndExist() {