-
-
Save rafaeltoledo/969a855bc17ff8f4033003460d71d746 to your computer and use it in GitHub Desktop.
Social App (coverage)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
... | |
testOptions { | |
unitTests.includeAndroidResources true | |
} | |
} | |
dependencies { | |
... | |
testImplementation 'org.robolectric:robolectric:3.8' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.rafaeltoledo.social | |
import org.junit.Assert.assertNotNull | |
import org.junit.Test | |
import org.junit.runner.RunWith | |
import org.robolectric.Robolectric | |
import org.robolectric.RobolectricTestRunner | |
@RunWith(RobolectricTestRunner::class) | |
class MainActivityTest { | |
@Test | |
fun checkIfActivityIsSuccessfullyCreated() { | |
assertNotNull(Robolectric.setupActivity(MainActivity::class.java)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'jacoco' | |
jacoco.toolVersion versions.jacoco | |
tasks.withType(Test) { | |
jacoco.includeNoLocationClasses = true | |
} | |
def classes = fileTree(dir: "$buildDir/tmp/kotlin-classes/debug") | |
def sources = files("$projectDir/src/main/kotlin") | |
def report = "$buildDir/reports/jacoco/report.xml" | |
task createCombinedCoverageReport(type: JacocoReport, | |
dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) { | |
sourceDirectories = sources | |
classDirectories = files(classes) | |
executionData = fileTree(dir: buildDir, includes: [ | |
'jacoco/testDebugUnitTest.exec', | |
'outputs/code-coverage/connected/*coverage.ec' | |
]) | |
reports { | |
xml.enabled = true | |
xml.destination file(report) | |
html.enabled = true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply plugin: 'org.jetbrains.kotlin.android' | |
apply from: "$rootDir/gradle/coverage.gradle" | |
android { | |
... | |
buildTypes { | |
debug { | |
testCoverageEnabled true | |
... | |
} | |
... | |
} | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
ext.versions = [ | |
'kotlin': '1.2.31', | |
'supportLibrary': '27.1.1', | |
'googleServices': '12.0.1', | |
'jacoco': '0.8.1' | |
] | |
repositories { | |
google() | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:3.1.1' | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin" | |
classpath 'com.google.gms:google-services:3.2.1' | |
classpath "org.jacoco:org.jacoco.core:$versions.jacoco" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// build.gradle | |
buildscript { | |
... | |
repositories { | |
google() | |
jcenter() | |
gradlePluginPortal() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:3.1.1' | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin" | |
classpath 'com.google.gms:google-services:3.2.1' | |
classpath "org.jacoco:org.jacoco.core:$versions.jacoco" | |
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// coverage.gradle | |
apply plugin: 'jacoco' | |
apply plugin: 'com.github.kt3k.coveralls' | |
... | |
def classes = fileTree(dir: "$buildDir/tmp/kotlin-classes/debug") | |
def sources = files("$projectDir/src/main/kotlin") | |
def report = "$buildDir/reports/jacoco/report.xml" | |
... | |
coveralls { | |
sourceDirs = sources.flatten() | |
jacocoReportPath = report | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2 | |
jobs: | |
build: | |
docker: | |
- image: circleci/android:api-27-alpha | |
working_directory: ~/social-app | |
environment: | |
JVM_OPTS: -Xmx3200m | |
CIRCLE_JDK_VERSION: oraclejdk8 | |
steps: | |
- checkout | |
- restore_cache: | |
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }} | |
- run: | |
name: Accept licenses | |
command: yes | sdkmanager --licenses || true | |
- run: | |
name: Decrypt release key | |
command: openssl aes-256-cbc -d -in distribution/release.keystore-cipher -out distribution/release.keystore -md sha256 -k $CIPHER_DECRYPT_KEY | |
- run: | |
name: Setup Google Services JSON | |
command: | | |
mkdir -p app/src/debug/ && touch app/src/debug/google-services.json | |
echo "${JSON_FIREBASE_DEVELOPMENT}" >> "app/src/debug/google-services.json" | |
mkdir -p app/src/release/ && touch app/src/release/google-services.json | |
echo "${JSON_FIREBASE_RELEASE}" >> "app/src/release/google-services.json" | |
- run: | |
name: Run Linters | |
command: ./gradlew check | |
- run: | |
name: Run Tests and generate Code Coverage | |
command: ./gradlew createCombinedCoverageReport | |
- run: | |
name: Upload code coverage data | |
command: ./gradlew coveralls | |
- run: | |
name: Build | |
command: ./gradlew assemble assembleAndroidTest | |
- store_artifacts: | |
path: app/build/reports/jacoco/createCombinedCoverageReport | |
destination: coverage-report | |
- store_artifacts: | |
path: app/build/reports/tests/testDebugUnitTest | |
destination: local-test-report | |
- save_cache: | |
paths: | |
- ~/.gradle | |
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment