diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index c10aaf3545..514d1accae 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -71,6 +71,15 @@ android { kotlinOptions { jvmTarget = "1.8" } + + sourceSets { + androidTest { + java.srcDirs += "src/sharedTest/java" + } + test { + java.srcDirs += "src/sharedTest/java" + } + } } static def gitRevision() { @@ -160,6 +169,8 @@ dependencies { testImplementation 'io.mockk:mockk:1.9.2.kotlin12' testImplementation 'org.amshove.kluent:kluent-android:1.44' testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" + // Plant Timber tree for test + testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1' androidTestImplementation 'androidx.test:core:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0' @@ -171,5 +182,6 @@ dependencies { androidTestImplementation 'io.mockk:mockk-android:1.9.2.kotlin12' androidTestImplementation "androidx.arch.core:core-testing:$arch_version" androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" - + // Plant Timber tree for test + androidTestImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1' } diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/InstrumentedTest.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/InstrumentedTest.kt index 56b358c69f..374a1fc399 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/InstrumentedTest.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/InstrumentedTest.kt @@ -18,10 +18,15 @@ package im.vector.matrix.android import android.content.Context import androidx.test.core.app.ApplicationProvider +import im.vector.matrix.android.test.shared.createTimberTestRule +import org.junit.Rule import java.io.File interface InstrumentedTest { + @Rule + fun timberTestRule() = createTimberTestRule() + fun context(): Context { return ApplicationProvider.getApplicationContext() } diff --git a/matrix-sdk-android/src/sharedTest/java/im/vector/matrix/android/test/shared/TestRules.kt b/matrix-sdk-android/src/sharedTest/java/im/vector/matrix/android/test/shared/TestRules.kt new file mode 100644 index 0000000000..77408322c1 --- /dev/null +++ b/matrix-sdk-android/src/sharedTest/java/im/vector/matrix/android/test/shared/TestRules.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.test.shared + +import net.lachlanmckee.timberjunit.TimberTestRule + +fun createTimberTestRule(): TimberTestRule { + return TimberTestRule.builder() + .showThread(false) + .showTimestamp(false) + .onlyLogWhenTestFails(false) + .build() +} diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/MatrixTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/MatrixTest.kt new file mode 100644 index 0000000000..cef9bb69d7 --- /dev/null +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/MatrixTest.kt @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android + +import im.vector.matrix.android.test.shared.createTimberTestRule +import org.junit.Rule + +interface MatrixTest { + + @Rule + fun timberTestRule() = createTimberTestRule() +} diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushRuleActionsTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushRuleActionsTest.kt index 1d5d6a4d19..21ea1cbd6a 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushRuleActionsTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushRuleActionsTest.kt @@ -16,6 +16,7 @@ package im.vector.matrix.android.api.pushrules +import im.vector.matrix.android.MatrixTest import im.vector.matrix.android.api.pushrules.rest.PushRule import im.vector.matrix.android.internal.di.MoshiProvider import org.junit.Assert.assertEquals @@ -23,7 +24,7 @@ import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue import org.junit.Test -class PushRuleActionsTest { +class PushRuleActionsTest: MatrixTest { @Test fun test_action_parsing() { diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt index 960d585bdc..1bf40222f8 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt @@ -16,6 +16,7 @@ package im.vector.matrix.android.api.pushrules +import im.vector.matrix.android.MatrixTest import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.toContent import im.vector.matrix.android.api.session.room.Room @@ -30,7 +31,7 @@ import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test -class PushrulesConditionTest { +class PushrulesConditionTest: MatrixTest { /* ========================================================================================== * Test EventMatchCondition diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/Base58Test.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/Base58Test.kt index 42295dada0..6d7ddce0b4 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/Base58Test.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/Base58Test.kt @@ -16,6 +16,7 @@ package im.vector.matrix.android.internal.crypto.keysbackup.util +import im.vector.matrix.android.MatrixTest import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertEquals import org.junit.FixMethodOrder @@ -23,7 +24,7 @@ import org.junit.Test import org.junit.runners.MethodSorters @FixMethodOrder(MethodSorters.JVM) -class Base58Test { +class Base58Test: MatrixTest { @Test fun encode() { diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/RecoveryKeyTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/RecoveryKeyTest.kt index 2566275952..606be13ed9 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/RecoveryKeyTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/keysbackup/util/RecoveryKeyTest.kt @@ -16,13 +16,15 @@ package im.vector.matrix.android.internal.crypto.keysbackup.util +import im.vector.matrix.android.MatrixTest import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test -class RecoveryKeyTest { +class RecoveryKeyTest: MatrixTest { + private val curve25519Key = byteArrayOf( 0x77.toByte(), 0x07.toByte(), 0x6D.toByte(), 0x0A.toByte(), 0x73.toByte(), 0x18.toByte(), 0xA5.toByte(), 0x7D.toByte(), 0x3C.toByte(), 0x16.toByte(), 0xC1.toByte(), 0x72.toByte(), 0x51.toByte(), 0xB2.toByte(), 0x66.toByte(), 0x45.toByte(), diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/store/db/HelperTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/store/db/HelperTest.kt index d4740bdc4f..b8524c95e0 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/store/db/HelperTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/store/db/HelperTest.kt @@ -16,11 +16,12 @@ package im.vector.matrix.android.internal.crypto.store.db +import im.vector.matrix.android.MatrixTest import im.vector.matrix.android.internal.util.md5 import org.junit.Assert.assertEquals import org.junit.Test -class HelperTest { +class HelperTest: MatrixTest { @Test fun testHash_ok() { diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/BinaryStringTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/BinaryStringTest.kt index df5499cb6f..8fc93c139e 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/BinaryStringTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/BinaryStringTest.kt @@ -16,13 +16,14 @@ package im.vector.matrix.android.internal.crypto.verification.qrcode +import im.vector.matrix.android.MatrixTest import org.amshove.kluent.shouldEqualTo import org.junit.FixMethodOrder import org.junit.Test import org.junit.runners.MethodSorters @FixMethodOrder(MethodSorters.JVM) -class BinaryStringTest { +class BinaryStringTest: MatrixTest { /** * I want to put bytes to a String, and vice versa diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/task/CoroutineSequencersTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/task/CoroutineSequencersTest.kt index a70713c44b..7d460861b1 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/task/CoroutineSequencersTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/task/CoroutineSequencersTest.kt @@ -16,6 +16,7 @@ package im.vector.matrix.android.internal.task +import im.vector.matrix.android.MatrixTest import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.delay @@ -26,7 +27,7 @@ import org.junit.Assert.assertEquals import org.junit.Test import java.util.concurrent.Executors -class CoroutineSequencersTest { +class CoroutineSequencersTest: MatrixTest { private val dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()