Merge pull request #6248 from vector-im/michaelk/sonar_on_vector

Improve Sonar coverage, including im.vector tests
This commit is contained in:
Michael Kaye 2022-06-10 14:38:06 +01:00 committed by GitHub
commit 027619aa01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 9 deletions

View File

@ -40,6 +40,7 @@ jobs:
- name: Run all the codecoverage tests at once - name: Run all the codecoverage tests at once
id: tests id: tests
uses: reactivecircus/android-emulator-runner@v2 uses: reactivecircus/android-emulator-runner@v2
continue-on-error: true
with: with:
api-level: 28 api-level: 28
arch: x86 arch: x86
@ -48,7 +49,8 @@ jobs:
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: ./gradlew theCodeCoverageReport --stacktrace $CI_GRADLE_ARG_PROPERTIES script: ./gradlew theCodeCoverageReport -Pandroid.testInstrumentationRunnerArguments.notPackage=im.vector.app.ui --stacktrace $CI_GRADLE_ARG_PROPERTIES
# NB: continue-on-error marks steps.tests.conclusion = 'success' but leaves stes.tests.outcome = 'failure'
- name: Run all the codecoverage tests at once (retry if emulator failed) - name: Run all the codecoverage tests at once (retry if emulator failed)
uses: reactivecircus/android-emulator-runner@v2 uses: reactivecircus/android-emulator-runner@v2
if: always() && steps.tests.outcome == 'failure' # don't run if previous step succeeded. if: always() && steps.tests.outcome == 'failure' # don't run if previous step succeeded.
@ -60,7 +62,7 @@ jobs:
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: ./gradlew theCodeCoverageReport --stacktrace $CI_GRADLE_ARG_PROPERTIES script: ./gradlew theCodeCoverageReport -Pandroid.testInstrumentationRunnerArguments.notPackage=im.vector.app.ui --stacktrace $CI_GRADLE_ARG_PROPERTIES
- run: ./gradlew sonarqube $CI_GRADLE_ARG_PROPERTIES - run: ./gradlew sonarqube $CI_GRADLE_ARG_PROPERTIES
if: always() # we may have failed a previous step and retried, that's OK if: always() # we may have failed a previous step and retried, that's OK
env: env:

View File

@ -25,7 +25,7 @@ buildscript {
classpath libs.gradle.kotlinPlugin classpath libs.gradle.kotlinPlugin
classpath libs.gradle.hiltPlugin classpath libs.gradle.hiltPlugin
classpath 'com.google.gms:google-services:4.3.10' classpath 'com.google.gms:google-services:4.3.10'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3' classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.4.0.2513'
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.5' classpath 'com.google.android.gms:oss-licenses-plugin:0.10.5'
classpath "com.likethesalad.android:stem-plugin:2.1.1" classpath "com.likethesalad.android:stem-plugin:2.1.1"
classpath 'org.owasp:dependency-check-gradle:7.1.0.1' classpath 'org.owasp:dependency-check-gradle:7.1.0.1'

View File

@ -1,4 +1,26 @@
def excludes = [ ] def excludes = [
// dependency injection graph
'**/*Module.*',
'**/*Module*.*',
// Framework entry points
'**/*Activity*',
'**/*Fragment*',
'**/*Application*',
// We would like to exclude android widgets as well but our naming is inconsistent
// Proof of concept
'**/*Login2*',
// Generated
'**/*JsonAdapter*',
'**/*Item.*',
'**/*$Holder.*',
'**/*ViewHolder.*',
'**/*View.*',
'**/*BottomSheet.*'
]
def initializeReport(report, projects, classExcludes) { def initializeReport(report, projects, classExcludes) {
projects.each { project -> project.apply plugin: 'jacoco' } projects.each { project -> project.apply plugin: 'jacoco' }
@ -56,8 +78,9 @@ task theCodeCoverageReport(type: JacocoReport) {
} }
def projects = collectProjects { ['vector','matrix-sdk-android'].contains(it.name) } def projects = collectProjects { ['vector','matrix-sdk-android'].contains(it.name) }
dependsOn { dependsOn {
[':matrix-sdk-android:testDebugUnitTest'] +
[':vector:testGplayDebugUnitTest'] + [':vector:testGplayDebugUnitTest'] +
[':vector:connectedGplayDebugAndroidTest'] +
[':matrix-sdk-android:testDebugUnitTest'] +
[':matrix-sdk-android:connectedDebugAndroidTest'] [':matrix-sdk-android:connectedDebugAndroidTest']
} }
initializeReport(it, projects, excludes) initializeReport(it, projects, excludes)

View File

@ -31,6 +31,7 @@ import androidx.test.filters.LargeTest
import im.vector.app.features.MainActivity import im.vector.app.features.MainActivity
import im.vector.app.features.home.HomeActivity import im.vector.app.features.home.HomeActivity
import org.hamcrest.CoreMatchers.not import org.hamcrest.CoreMatchers.not
import org.junit.Ignore
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -38,6 +39,7 @@ import kotlin.random.Random
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
@LargeTest @LargeTest
@Ignore
class RegistrationTest { class RegistrationTest {
@get:Rule @get:Rule

View File

@ -44,6 +44,7 @@ import im.vector.app.features.crypto.recover.SetupMode
import im.vector.app.features.home.HomeActivity import im.vector.app.features.home.HomeActivity
import org.hamcrest.CoreMatchers.not import org.hamcrest.CoreMatchers.not
import org.junit.Before import org.junit.Before
import org.junit.Ignore
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -52,6 +53,7 @@ import kotlin.random.Random
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
@LargeTest @LargeTest
@Ignore
class SecurityBootstrapTest : VerificationTestBase() { class SecurityBootstrapTest : VerificationTestBase() {
var existingSession: Session? = null var existingSession: Session? = null

View File

@ -38,6 +38,7 @@ import im.vector.app.features.MainActivity
import im.vector.app.features.home.HomeActivity import im.vector.app.features.home.HomeActivity
import org.hamcrest.CoreMatchers.not import org.hamcrest.CoreMatchers.not
import org.junit.Before import org.junit.Before
import org.junit.Ignore
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -57,6 +58,7 @@ import kotlin.random.Random
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
@LargeTest @LargeTest
@Ignore
class VerifySessionInteractiveTest : VerificationTestBase() { class VerifySessionInteractiveTest : VerificationTestBase() {
var existingSession: Session? = null var existingSession: Session? = null

View File

@ -43,6 +43,7 @@ import im.vector.app.features.crypto.recover.SetupMode
import im.vector.app.features.home.HomeActivity import im.vector.app.features.home.HomeActivity
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.junit.Before import org.junit.Before
import org.junit.Ignore
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@ -57,6 +58,7 @@ import kotlin.random.Random
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
@LargeTest @LargeTest
@Ignore
class VerifySessionPassphraseTest : VerificationTestBase() { class VerifySessionPassphraseTest : VerificationTestBase() {
var existingSession: Session? = null var existingSession: Session? = null

View File

@ -24,14 +24,14 @@ class TemporaryStoreTest {
@Test @Test
fun testTemporaryStore() { fun testTemporaryStore() {
// Keep the data 30 millis // Keep the data 300 millis
val store = TemporaryStore<String>(30) val store = TemporaryStore<String>(300)
store.data = "test" store.data = "test"
store.data shouldBe "test" store.data shouldBe "test"
sleep(15) sleep(10)
store.data shouldBe "test" store.data shouldBe "test"
sleep(20) sleep(300)
store.data shouldBe null store.data shouldBe null
} }
} }

View File

@ -29,6 +29,7 @@ import im.vector.app.InstrumentedTest
import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldBeTrue import org.amshove.kluent.shouldBeTrue
import org.junit.FixMethodOrder import org.junit.FixMethodOrder
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.junit.runners.JUnit4 import org.junit.runners.JUnit4
@ -38,6 +39,7 @@ import java.util.concurrent.TimeUnit
@RunWith(JUnit4::class) @RunWith(JUnit4::class)
@FixMethodOrder(MethodSorters.JVM) @FixMethodOrder(MethodSorters.JVM)
@Ignore
class SpanUtilsTest : InstrumentedTest { class SpanUtilsTest : InstrumentedTest {
private val spanUtils = SpanUtils { private val spanUtils = SpanUtils {