Skip to content

Commit

Permalink
Add impact sample app. Fix some things while creating it (#556)
Browse files Browse the repository at this point in the history
MBS-9347 Add impact sample app
rename ReportType.kt to ConfigurationType.kt
disable impact efficiency calculation when there are no tests
add InstrumentationTestImpactAnalysisExtension.kt output default value
  • Loading branch information
sboishtyan authored Aug 30, 2020
1 parent 5f9e84d commit f730723
Show file tree
Hide file tree
Showing 37 changed files with 331 additions and 42 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ record_sreenshots:
-Pandroid.testInstrumentationRunnerArguments.annotation=com.avito.android.test.annotations.ScreenshotTest \
-Pandroid.testInstrumentationRunnerArguments.recordScreenshots=true
./gradlew samples:test-app-screenshot-test:recordScreenshots

analyzeImpactOnSampleApp:
./gradlew samples:test-app-impact:app:analyzeTestImpact -PtargetBranch=develop $(params)
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ plugins {
id("org.jetbrains.kotlin.jvm") apply false
id("com.android.application") apply false
id("com.avito.android.instrumentation-tests") apply false
id("com.avito.android.impact")
}

/**
Expand Down
22 changes: 22 additions & 0 deletions samples/test-app-impact/androidTest-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id("com.android.library")
id("kotlin-android")
}

android {

/**
* Disable all buildTypes except testing
* to avoid confusing errors in IDE if wrong build variant is selected
*/
variantFilter {
if (name != testBuildType) {
ignore = true
logger.debug("Build variant $name is omitted for module: $path")
}
}

testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest
package="com.avito.android.sample.impact.test.core">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.avito.android.sample.impact

interface ImpactScreenMarker {
val id: Int
}
43 changes: 43 additions & 0 deletions samples/test-app-impact/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import com.avito.instrumentation.impact.InstrumentationTestImpactAnalysisExtension

plugins {
id("com.android.application")
id("kotlin-android")
id("com.avito.android.instrumentation-test-impact-analysis")
}

android {

defaultConfig {
versionName = "1.0"
versionCode = 1
}

/**
* Disable all buildTypes except testing
* to avoid confusing errors in IDE if wrong build variant is selected
*/
variantFilter {
if (name != testBuildType) {
ignore = true
logger.debug("Build variant $name is omitted for module: $path")
}
}

testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}

extensions.configure<InstrumentationTestImpactAnalysisExtension> {
screenMarkerClass.set("com.avito.android.sample.impact.ImpactScreenMarker")
screenMarkerMetadataField.set("id")
}

dependencies {
implementation(project(":samples:test-app-impact:feature-one"))
implementation(project(":samples:test-app-impact:feature-two"))
implementation(Dependencies.appcompat)
androidTestImplementation(Dependencies.test.junit)
androidTestImplementation(project(":samples:test-app-impact:androidTest-core"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import com.avito.android.samples.impact.screen.FeatureOneScreen
import org.junit.Test

class FeatureOneTest {
@Test
fun test() {
FeatureOneScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import com.avito.android.samples.impact.screen.FeatureTwoScreen
import org.junit.Test

class FeatureTwoTest {
@Test
fun test() {
FeatureTwoScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class NotATest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import org.junit.Test

class WithoutScreenTest {

@Test
fun test() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.avito.android.samples.impact.screen

import com.avito.android.sample.impact.ImpactScreenMarker
import com.avito.android.sample.impact.R

class AppScreen : ImpactScreenMarker {
override val id: Int = R.layout.activity_app
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.avito.android.samples.impact.screen

import org.junit.Test

class AppTest {

@Test
fun test() {
AppScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.avito.android.samples.impact.screen

import com.avito.android.sample.impact.ImpactScreenMarker
import com.avito.android.sample.impact.R

class FeatureOneScreen : ImpactScreenMarker {
override val id: Int = R.layout.activity_feature_one
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.avito.android.samples.impact.screen

import com.avito.android.sample.impact.ImpactScreenMarker
import com.avito.android.sample.impact.R

class FeatureTwoScreen : ImpactScreenMarker {
override val id: Int = R.layout.activity_feature_two
}
12 changes: 12 additions & 0 deletions samples/test-app-impact/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.avito.android.sample.impact">

<application
android:allowBackup="false"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".AppActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.avito.android.sample.impact

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class AppActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_app)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AppActivity">

</FrameLayout>
25 changes: 25 additions & 0 deletions samples/test-app-impact/feature-one/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id("com.android.library")
id("kotlin-android")
}

android {

/**
* Disable all buildTypes except testing
* to avoid confusing errors in IDE if wrong build variant is selected
*/
variantFilter {
if (name != testBuildType) {
ignore = true
logger.debug("Build variant $name is omitted for module: $path")
}
}

testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
dependencies {
implementation(Dependencies.appcompat)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.avito.android.sample.impact.feature_one">

<application>
<activity android:name=".FeatureOneActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.avito.android.sample.impact.feature_one

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class FeatureOneActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_feature_one)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FeatureOneActivity">

</FrameLayout>
25 changes: 25 additions & 0 deletions samples/test-app-impact/feature-two/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id("com.android.library")
id("kotlin-android")
}

android {

/**
* Disable all buildTypes except testing
* to avoid confusing errors in IDE if wrong build variant is selected
*/
variantFilter {
if (name != testBuildType) {
ignore = true
logger.debug("Build variant $name is omitted for module: $path")
}
}

testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
dependencies {
implementation(Dependencies.appcompat)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.avito.android.sample.impact.feature_two">

<application>
<activity android:name=".FeatureTwoActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.avito.android.sample.impact.feature_two

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class FeatureTwoActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_feature_two)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FeatureTwoActivity">

</FrameLayout>
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ if (useCompositeBuild.toBoolean()) {
}
include(":samples:test-app-core")
include(":samples:test-app-screenshot-test")
include(":samples:test-app-impact:app")
include(":samples:test-app-impact:androidTest-core")
include(":samples:test-app-impact:feature-one")
include(":samples:test-app-impact:feature-two")

includeBuild("buildscript")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import java.io.File
class BytecodeResolver(
private val project: Project
) {
fun resolveBytecode(reportType: ReportType): Set<File> =
project.internalModule.getConfiguration(reportType).fullBytecodeSets
fun resolveBytecode(configurationType: ConfigurationType): Set<File> =
project.internalModule.getConfiguration(configurationType).fullBytecodeSets

fun resolveBytecodeWithoutDependencyToAnotherConfigurations(reportType: ReportType): Set<File> =
project.internalModule.getConfiguration(reportType).let { configuration ->
fun resolveBytecodeWithoutDependencyToAnotherConfigurations(configurationType: ConfigurationType): Set<File> =
project.internalModule.getConfiguration(configurationType).let { configuration ->
configuration.bytecodeSets() + configuration.dependencies.flatMap { it.fullBytecodeSets }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.avito.impact

enum class ConfigurationType { IMPLEMENTATION, UNIT_TESTS, ANDROID_TESTS, LINT }
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class ModifiedProjectsFinder(
fallbackDetector.isFallback is ImpactFallbackDetector.Result.Skip
}

fun findModifiedProjects(reportType: ReportType? = null): Set<ModifiedProject> {
val reportTypes = if (reportType == null) {
ReportType.values()
fun findModifiedProjects(configurationType: ConfigurationType? = null): Set<ModifiedProject> {
val reportTypes = if (configurationType == null) {
ConfigurationType.values()
} else {
arrayOf(reportType)
arrayOf(configurationType)
}
return reportTypes
.flatMap { type ->
Expand All @@ -29,17 +29,17 @@ class ModifiedProjectsFinder(
}

@Deprecated("Используется только для поиска по ReportType.ANDROID_TESTS. Оптимизация для UI тестов, явно игнорируем изменения в реализации, чтобы не сваливаться всегда в fallback")
fun findModifiedProjectsWithoutDependencyToAnotherConfigurations(reportType: ReportType): Set<ModifiedProject> =
findProjects(rootProject, reportType) {
it.internalModule.getConfiguration(reportType).let { configuration ->
fun findModifiedProjectsWithoutDependencyToAnotherConfigurations(configurationType: ConfigurationType): Set<ModifiedProject> =
findProjects(rootProject, configurationType) {
it.internalModule.getConfiguration(configurationType).let { configuration ->
configuration.dependencies.any { dependency -> dependency.isModified }
|| configuration.hasChangedFiles
}
}

private fun findProjects(
rootProject: Project,
reportType: ReportType,
configurationType: ConfigurationType,
predicate: (project: Project) -> Boolean
): Set<ModifiedProject> {
val projects = if (skipAnalysis) {
Expand All @@ -52,7 +52,7 @@ class ModifiedProjectsFinder(
.map {
ModifiedProject(
project = it,
changedFiles = it.internalModule.getConfiguration(reportType)
changedFiles = it.internalModule.getConfiguration(configurationType)
.changedFiles()
.getOrElse { emptyList() }
)
Expand Down

This file was deleted.

Loading

0 comments on commit f730723

Please sign in to comment.