-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from DataDog/yl/kcp/add-instrumented-module
RUM-8600: Add instrumented test module for kotlin compiler plugin
- Loading branch information
Showing
7 changed files
with
179 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import com.datadog.gradle.config.AndroidConfig | ||
|
||
plugins { | ||
id("com.android.application") | ||
id("org.jetbrains.kotlin.android") | ||
alias(libs.plugins.compose.compiler) | ||
} | ||
|
||
android { | ||
namespace = "com.datadog.android.instrumented" | ||
compileSdk = AndroidConfig.TARGET_SDK | ||
|
||
defaultConfig { | ||
applicationId = "com.datadog.android.instrumented" | ||
// Min SDK must be higher than 30 to make Android instrumented test support | ||
// space characters in function names | ||
minSdk = AndroidConfig.TARGET_SDK | ||
targetSdk = AndroidConfig.TARGET_SDK | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "11" | ||
} | ||
buildFeatures { | ||
compose = true | ||
} | ||
packaging { | ||
resources { | ||
excludes += "/META-INF/{AL2.0,LGPL2.1}" | ||
merges += "META-INF/LICENSE.md" | ||
merges += "META-INF/LICENSE-notice.md" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
kotlinCompilerPluginClasspath(project(":dd-sdk-android-gradle-plugin")) | ||
implementation(libs.androidx.core) | ||
implementation(libs.androidx.lifecycle.runtime.ktx) | ||
implementation(libs.androidx.activity.compose) | ||
implementation(platform(libs.androidx.compose.bom)) | ||
implementation(libs.androidx.ui) | ||
implementation(libs.androidx.ui.graphics) | ||
implementation(libs.androidx.ui.tooling.preview) | ||
implementation(libs.androidx.material3) | ||
androidTestImplementation(libs.androidx.junit) | ||
androidTestImplementation(libs.bundles.jUnit5) | ||
androidTestImplementation(libs.bundles.testTools) | ||
androidTestImplementation(libs.androidx.espresso.core) | ||
androidTestImplementation(platform(libs.androidx.compose.bom)) | ||
androidTestImplementation(libs.androidx.ui.test.junit4) | ||
debugImplementation(libs.androidx.ui.tooling) | ||
debugImplementation(libs.androidx.ui.test.manifest) | ||
} |
47 changes: 47 additions & 0 deletions
47
instrumented/src/androidTest/java/com/datadog/android/instrumented/SemanticsTest.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,47 @@ | ||
package com.datadog.android.instrumented | ||
|
||
import androidx.compose.ui.test.SemanticsMatcher | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import fr.xgouchet.elmyr.junit5.ForgeExtension | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.junit.jupiter.api.extension.Extensions | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.junit.jupiter.MockitoSettings | ||
import org.mockito.quality.Strictness | ||
|
||
@Extensions( | ||
ExtendWith(MockitoExtension::class), | ||
ExtendWith(ForgeExtension::class) | ||
) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
class SemanticsTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun `M have no datadog semantics tag W compose kotlin compiler plugin is not registered`() { | ||
composeTestRule.setContent { | ||
TestScreen() | ||
} | ||
val semanticsMatcher = hasSemanticsValue(DD_SEMANTICS_KEY_NAME, DD_SEMANTICS_VALUE_DEFAULT) | ||
composeTestRule.onNode(semanticsMatcher).assertDoesNotExist() | ||
} | ||
|
||
private fun <T> hasSemanticsValue( | ||
keyName: String, | ||
expectedValue: T | ||
): SemanticsMatcher { | ||
return SemanticsMatcher("$keyName = $expectedValue") { node -> | ||
val entry = node.config.firstOrNull { it.key.name == keyName } | ||
entry != null && entry.value == expectedValue | ||
} | ||
} | ||
|
||
companion object { | ||
private const val DD_SEMANTICS_KEY_NAME = "_dd_semantics" | ||
private const val DD_SEMANTICS_VALUE_DEFAULT = "DD_DEFAULT_TAG" | ||
} | ||
} |
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,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
12 changes: 12 additions & 0 deletions
12
instrumented/src/main/java/com/datadog/android/instrumented/TestScreen.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,12 @@ | ||
package com.datadog.android.instrumented | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
internal fun TestScreen() { | ||
Column { | ||
Text("") | ||
} | ||
} |
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