Skip to content

Commit 54637f7

Browse files
committed
Added tests for Android project and aggregation plugin
1 parent d837e39 commit 54637f7

File tree

16 files changed

+277
-0
lines changed

16 files changed

+277
-0
lines changed

kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/SettingsPluginTests.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,14 @@ internal class SettingsPluginTests {
8282
classCounter("tests.settings.subproject.SubprojectClass").assertAbsent()
8383
}
8484
}
85+
86+
@TemplateTest("settings-plugin-android", ["-Pkover", ":app:testDebugUnitTest", "koverXmlReport"])
87+
fun CheckerContext.testAndroid() {
88+
xmlReport {
89+
classCounter("kotlinx.kover.test.android.MainClass").assertCovered()
90+
classCounter("kotlinx.kover.test.android.DebugClass").assertFullyMissed()
91+
classCounter("kotlinx.kover.test.android.ReleaseClass").assertAbsent()
92+
classCounter("kotlinx.kover.test.android.LocalTests").assertAbsent()
93+
}
94+
}
8595
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
plugins {
6+
id ("com.android.application")
7+
id ("org.jetbrains.kotlin.android")
8+
}
9+
10+
android {
11+
namespace = "kotlinx.kover.test.android"
12+
compileSdk = 32
13+
14+
defaultConfig {
15+
applicationId = "kotlinx.kover.test.android"
16+
minSdk = 21
17+
targetSdk = 31
18+
versionCode = 1
19+
versionName = "1.0"
20+
21+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
22+
}
23+
24+
buildTypes {
25+
release {
26+
isMinifyEnabled = true
27+
}
28+
}
29+
compileOptions {
30+
sourceCompatibility = JavaVersion.VERSION_1_8
31+
targetCompatibility = JavaVersion.VERSION_1_8
32+
}
33+
kotlinOptions {
34+
jvmTarget = "1.8"
35+
}
36+
buildFeatures {
37+
viewBinding = true
38+
}
39+
}
40+
41+
dependencies {
42+
implementation("androidx.core:core-ktx:1.8.0")
43+
implementation("androidx.appcompat:appcompat:1.5.0")
44+
implementation("com.google.android.material:material:1.6.1")
45+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
46+
testImplementation("junit:junit:4.13.2")
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.kover.test.android
6+
7+
object DebugClass {
8+
fun log(message: String) {
9+
println("DEBUG: $message")
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4+
-->
5+
6+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
7+
8+
<application android:label="@string/app_name">
9+
<uses-library android:name="com.google.android.things" android:required="false" />
10+
11+
<activity android:name=".MainActivity"
12+
android:exported="true">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
<!-- Make this the first activity that is displayed when the device boots. -->
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.HOME" />
23+
<category android:name="android.intent.category.DEFAULT" />
24+
</intent-filter>
25+
</activity>
26+
</application>
27+
28+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kotlinx.kover.test.android
2+
3+
import android.os.Bundle
4+
import android.app.Activity
5+
6+
class MainActivity : Activity() {
7+
8+
override fun onCreate(savedInstanceState: Bundle?) {
9+
super.onCreate(savedInstanceState)
10+
setContentView(R.layout.activity_main)
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.kover.test.android
6+
7+
class MainClass {
8+
fun log(message: String) {
9+
println("DEBUG: $message")
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4+
-->
5+
6+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
7+
xmlns:app="http://schemas.android.com/apk/res-auto"
8+
xmlns:tools="http://schemas.android.com/tools"
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent"
11+
tools:context=".MainActivity">
12+
13+
<TextView
14+
android:id="@+id/main_label"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:layout_marginStart="104dp"
18+
android:layout_marginTop="28dp"
19+
android:text="SERIALIZATION TEST"
20+
android:textSize="20sp"
21+
android:textStyle="bold"
22+
app:layout_constraintStart_toStartOf="parent"
23+
app:layout_constraintTop_toTopOf="parent" />
24+
25+
<EditText
26+
android:id="@+id/encoded_text"
27+
android:layout_width="373dp"
28+
android:layout_height="411dp"
29+
android:layout_marginStart="16dp"
30+
android:layout_marginTop="16dp"
31+
android:editable="false"
32+
android:ems="10"
33+
android:gravity="start|top"
34+
android:inputType="textMultiLine"
35+
android:textAlignment="viewStart"
36+
android:textSize="12sp"
37+
app:layout_constraintStart_toStartOf="parent"
38+
app:layout_constraintTop_toBottomOf="@+id/main_label" />
39+
40+
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4+
-->
5+
6+
<resources>
7+
<color name="purple_200">#FFBB86FC</color>
8+
<color name="purple_500">#FF6200EE</color>
9+
<color name="purple_700">#FF3700B3</color>
10+
<color name="teal_200">#FF03DAC5</color>
11+
<color name="teal_700">#FF018786</color>
12+
<color name="black">#FF000000</color>
13+
<color name="white">#FFFFFFFF</color>
14+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!--
2+
~ Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
-->
4+
5+
<resources>
6+
<string name="app_name">Android Test</string>
7+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!--
2+
~ Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
-->
4+
5+
<resources>
6+
7+
<style name="Theme.App" parent="android:Theme.Material.Light.DarkActionBar" />
8+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.kover.test.android
6+
7+
object ReleaseClass {
8+
fun log(message: String) {
9+
println("DEBUG: $message")
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.kover.test.android
6+
7+
import org.junit.Test
8+
9+
import org.junit.Assert.*
10+
11+
12+
class LocalTests {
13+
@Test
14+
fun test() {
15+
MainClass().log("test")
16+
}
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
plugins {
6+
id("com.android.application") version "7.4.0" apply false
7+
id("com.android.library") version "7.4.0" apply false
8+
id("org.jetbrains.kotlin.android") version "1.8.20" apply false
9+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
#
4+
5+
# Project-wide Gradle settings.
6+
# IDE (e.g. Android Studio) users:
7+
# Gradle settings configured through the IDE *will override*
8+
# any settings specified in this file.
9+
# For more details on how to configure your build environment visit
10+
# http://www.gradle.org/docs/current/userguide/build_environment.html
11+
# Specifies the JVM arguments used for the daemon process.
12+
# The setting is particularly useful for tweaking memory settings.
13+
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
14+
# When configured, Gradle will run in incubating parallel mode.
15+
# This option should only be used with decoupled projects. More details, visit
16+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17+
# org.gradle.parallel=true
18+
# AndroidX package structure to make it clearer which packages are bundled with the
19+
# Android operating system, and which are packaged with your app's APK
20+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
21+
android.useAndroidX=true
22+
# Kotlin code style for this project: "official" or "obsolete":
23+
kotlin.code.style=official
24+
# Enables namespacing of each library's R class so that its R class includes only the
25+
# resources declared in the library itself and none from the library's dependencies,
26+
# thereby reducing the size of the R class for that library
27+
android.nonTransitiveRClass=true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pluginManagement {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
gradlePluginPortal()
6+
}
7+
}
8+
9+
dependencyResolutionManagement {
10+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11+
repositories {
12+
google()
13+
mavenCentral()
14+
gradlePluginPortal()
15+
}
16+
}
17+
18+
plugins {
19+
id("org.jetbrains.kotlinx.kover.aggregation") version "SNAPSHOT"
20+
}
21+
22+
rootProject.name = "android_and_aggregation"
23+
include(":app")

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/aggregation/project/KoverProjectGradlePlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import kotlinx.kover.gradle.aggregation.project.instrumentation.InstrumentationF
2020
import kotlinx.kover.gradle.aggregation.project.instrumentation.JvmOnFlyInstrumenter
2121
import kotlinx.kover.gradle.aggregation.project.tasks.ArtifactGenerationTask
2222
import kotlinx.kover.gradle.aggregation.project.tasks.KoverAgentSearchTask
23+
import kotlinx.kover.gradle.plugin.commons.KOTLIN_ANDROID_PLUGIN_ID
2324
import kotlinx.kover.gradle.plugin.commons.KoverCriticalException
2425
import org.gradle.api.Plugin
2526
import org.gradle.api.Project

0 commit comments

Comments
 (0)