Skip to content

Instantly share code, notes, and snippets.

View mfebrianto's full-sized avatar

michael febrianto mfebrianto

View GitHub Profile
@mfebrianto
mfebrianto / android.yml
Created March 14, 2023 23:10
github action config for android with jacoco coverage test
jobs:
android:
name: android
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Clone repo
uses: actions/checkout@v2
- name: Set up JDK 11
@mfebrianto
mfebrianto / build.gradle
Last active March 14, 2023 22:32
build.gradle for jacoco config on unit test only
// gradle plugin has jacoco that you can use to make your life easier without the
// hassle of manually import and ensure the compatibility
apply plugin: 'jacoco'
jacoco {
// if you are using java 11 then jacoco version that support it is v0.8.7
toolVersion = "0.8.7"
// this is where you find html/xml/csv report for your unit test coverage check
reportsDirectory = file("$buildDir/reports/coverage")
@mfebrianto
mfebrianto / read_screen_test.mocks.dart
Created March 8, 2023 22:20
read_screen_test.mocks.dart
@override
_i3.Future<String> getDoc(String? id) => (super.noSuchMethod(
Invocation.method(
#getDoc,
[id],
),
returnValue: _i3.Future<String>.value(''),
returnValueForMissingStub: _i3.Future<String>.value(''),
) as _i3.Future<String>);
@override
_i3.Future<String> getDoc(String? id) => (super.noSuchMethod(
Invocation.method(
#getDoc,
[id],
),
returnValue: _i3.Future<String>.value(''),
) as _i3.Future<String>);
class ReadScreen extends StatefulWidget {
final String bookId;
final LibraryService libraryService;
const ReadScreen({
Key? key,
required this.bookId,
this.libraryService = const LibraryService(),
}) : super(key: key);
task jacocoTestCoverageVerification(type: JacocoCoverageVerification, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
group = "Verification"
description = "Check code coverage"
onlyIf = {
true
}
violationRules {
rule {
apply plugin: 'jacoco'
android {
debug {
// this line will add new task createDebugCoverageReport that needed by jacoco
// however as default it will generate coverage for androidTest
// it does not generate coverage for unitTest
testCoverageEnabled true
}
}
buildscript {
ext.jacocoVersion = '0.8.7'
repositories {
google()
jcenter()
}
dependencies {
classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
class IronManMk1Debug {
fun shoot() {
println("jarvis: target destroyed")
}
fun getRepulsorsStatus() {
println("jarvis: repulsors no power")
}
val repulsorsStatus = println("jarvis: repulsors no power")
class IronManMk2 {
fun getRepulsorsStatus() {
println("jarvis: ready power 100")
}
val repulsorsStatus get() = println("jarvis: ready power 90")
}