-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
aggregateTestCoverage
support on testAggregatedReport
- Loading branch information
Showing
12 changed files
with
193 additions
and
38 deletions.
There are no files selected for viewing
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
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
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
13 changes: 13 additions & 0 deletions
13
demo-project/app/src/main/java/com/example/myapplication/SomeSingleton.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.myapplication | ||
|
||
object SomeSingleton { | ||
|
||
fun doStuff() { | ||
println("stuff") | ||
} | ||
|
||
fun doMoreStuff() { | ||
println("more stuff") | ||
} | ||
|
||
} |
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
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
25 changes: 25 additions & 0 deletions
25
...roject/ui-tests/src/main/kotlin/com/example/myapplication/SomeSingletonMoreStuffUITest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.myapplication | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class SomeSingletonMoreStuffUITest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.example.app", appContext.packageName) | ||
|
||
SomeSingleton.doMoreStuff() // to mark coverage of UI tests | ||
} | ||
} | ||
|
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
59 changes: 59 additions & 0 deletions
59
plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AGPInternalAPIAccessor.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
@file:Suppress("PrivateAPI", "ObjectPropertyName") | ||
|
||
/** | ||
* Helper to access AGP internal API as the required wiring to get coverage data is not public | ||
*/ | ||
|
||
package io.github.gmazzo.android.test.aggregation | ||
|
||
import com.android.build.api.artifact.Artifact | ||
import com.android.build.api.artifact.Artifacts | ||
import com.android.build.api.artifact.impl.ArtifactsImpl | ||
import com.android.build.api.artifact.impl.InternalScopedArtifact | ||
import com.android.build.api.artifact.impl.ScopedArtifactsImpl | ||
import com.android.build.api.component.analytics.AnalyticsEnabledArtifacts | ||
import com.android.build.api.component.analytics.AnalyticsEnabledScopedArtifacts | ||
import com.android.build.api.variant.ScopedArtifacts | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.FileSystemLocation | ||
import org.gradle.api.provider.Provider | ||
import kotlin.reflect.full.functions | ||
import kotlin.reflect.full.memberProperties | ||
import kotlin.reflect.jvm.isAccessible | ||
import kotlin.reflect.typeOf | ||
|
||
internal fun <FILE_TYPE : FileSystemLocation> Artifacts.get( | ||
type: Artifact.Single<FILE_TYPE> | ||
): Provider<FILE_TYPE> = when (this) { | ||
is ArtifactsImpl -> get(type) | ||
is AnalyticsEnabledArtifacts -> delegate.get(type) | ||
else -> error("Unknown `Artifacts` type: $this") | ||
} | ||
|
||
internal fun ScopedArtifacts.get(type: InternalScopedArtifact): ConfigurableFileCollection = | ||
when (this) { | ||
is ScopedArtifactsImpl -> _getScopedArtifactsContainer(type).finalScopedContent | ||
is AnalyticsEnabledScopedArtifacts -> _delegate.get(type) | ||
else -> error("Unknown `ScopedArtifacts` type: $this") | ||
} | ||
|
||
private fun ScopedArtifactsImpl._getScopedArtifactsContainer(type: InternalScopedArtifact) = | ||
ScopedArtifactsImpl::class | ||
.functions | ||
.firstOrNull { | ||
it.name == "getScopedArtifactsContainer" && | ||
it.parameters.size == 2 && | ||
it.parameters[0].type == typeOf<ScopedArtifactsImpl>() && | ||
it.parameters[1].type == typeOf<InternalScopedArtifact>() | ||
} | ||
?.apply { isAccessible = true } | ||
?.call(this, type) as? ScopedArtifactsImpl.ScopedArtifactsContainer | ||
?: error("Can't get `InternalScopedArtifact` type `$type`") | ||
|
||
private val AnalyticsEnabledScopedArtifacts._delegate | ||
get() = AnalyticsEnabledScopedArtifacts::class | ||
.memberProperties | ||
.firstOrNull { it.name == "delegate" } | ||
?.apply { isAccessible = true } | ||
?.get(this) as ScopedArtifacts? | ||
?: error("Can't get `AnalyticsEnabledScopedArtifacts`'s delegate") |
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
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
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