Ошибка установки Android Kotlin Cucumber, тест не обнаруженAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Ошибка установки Android Kotlin Cucumber, тест не обнаружен

Сообщение Anonymous »

Я пытаюсь настроить Cucumber для своего проекта Android.
Я использую Kotlin.
У меня проблема: когда я запускаю тест, сборка завершается. но говорит 0 тестов.
вот мой репозиторий
Результатом, который я ожидаю, является запуск теста огурца и выполнение единственного 1 теста, который у меня есть на данный момент.
Я пробовал помещать файлы в разные места и менять пакет имена, и меняем
здесь мои хирачи и файлы

Код: Выделить всё

project/
│
├── build/
│
├── src/
│   ├── androidTest/
│   ├── assets/
│   ├── kotlin/
│   │   └── com.kirabitm.relayance/
│   ├── resources/
│   ├── steps/
│   │   └── AddCustomerSteps/
│   ├── test/
│   │   ├── CucumberOptions.kt
│   │   ├── util/
│   │   │   ├── clickOnCustomerLaunchesDetailAc/
│   │   │   ├── customerDetailsAreCorrectTest.kt
│   │   │   ├── ExampleInstrumentedTest/
│   │   │   └── numberOfCustomersInList/
│   │   ├── resources/
│   │   └── features/
│   │       └── add_new_customer.feature/
│   ├── assets/
│   └── main/
│       └── java/
│           └── com.kirabitm.relayance/
│
└── other files and directories...

Код: Выделить всё

import com.android.build.gradle.BaseExtension

plugins {
// alias(libs.plugins.androidApplication)
//alias(libs.plugins.jetbrainsKotlinAndroid)
id("com.android.application") // Apply the Android Gradle Plugin
id("org.jetbrains.kotlin.android") // Apply the Kotlin Android Plugin
id("jacoco")
id("kotlin-kapt")
id("com.google.dagger.hilt.android")
}
tasks.withType {
extensions.configure(JacocoTaskExtension::class) {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
}

android {
namespace = "com.kirabium.relayance"
compileSdk = 35

testCoverage {
version = "0.8.8"
}

defaultConfig {
applicationId = "com.kirabium.relayance"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

//testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
//testInstrumentationRunner = "runner.CucumberTestRunner"
testInstrumentationRunner = "io.cucumber.android.runner.CucumberAndroidJUnitRunner"

vectorDrawables {
useSupportLibrary = true
}
}

buildFeatures {
viewBinding = true
}

sourceSets.all {
println("Source set: ${name} ->  ${java.srcDirs}")
}

sourceSets {
getByName("androidTest") {
java.srcDirs("src/androidTest/kotlin")
resources.srcDirs("src/androidTest/resources")
assets.srcDirs("src/androidTest/assets")

}
}

testOptions {
unitTests.all {
// Add the following line to make the task untracked
it.doNotTrackState("")
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
debug {
enableAndroidTestCoverage = true
enableUnitTestCoverage = true
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_19
targetCompatibility = JavaVersion.VERSION_19
}
kotlinOptions {
jvmTarget = "19"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.15"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
excludes += "/META-INF/LICENSE.md"
excludes += "/META-INF/LICENSE-notice.md"
excludes += "/META-INF/NOTICE.md"
}
}
}

val androidExtension = extensions.getByType()

val jacocoTestReport by tasks.registering(JacocoReport::class) {
dependsOn("testDebugUnitTest", "createDebugCoverageReport")
group = "Reporting"
description = "Generate Jacoco coverage reports"

reports {
xml.required.set(true)
html.required.set(true)
}

val debugTree = fileTree("${buildDir}/tmp/kotlin-classes/debug")
val mainSrc = androidExtension.sourceSets.getByName("main").java.srcDirs

classDirectories.setFrom(debugTree)
sourceDirectories.setFrom(files(mainSrc))
executionData.setFrom(fileTree(buildDir) {
include("**/*.exec",  "**/*.ec")
})
}

dependencies {

implementation("org.junit.platform:junit-platform-suite-api:1.11.4")
//testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
//testRuntimeOnly ("org.junit.jupiter:junit-jupiter-engine:5.10.0")
//testImplementation ("org.junit.jupiter:junit-jupiter-params:5.10.0")

implementation(libs.androidx.junit.ktx)
implementation(libs.androidx.espresso.intents)
implementation(libs.androidx.ui.test.junit4.android)
implementation(libs.cucumber.android)
// Kotlin
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.0") // Updated to latest stable version

// Cucumber
implementation("io.cucumber:cucumber-java:7.20.1") // For Cucumber Java support
androidTestImplementation("io.cucumber:cucumber-android:7.14.0") // Cucumber Android integration
androidTestImplementation("io.cucumber:cucumber-junit:7.14.0")
androidTestImplementation("io.cucumber:cucumber-junit-rules-support:7.14.0")

// AndroidX Test (for instrumentation tests)
androidTestImplementation("androidx.test:runner:1.6.1")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation("androidx.test.espresso:espresso-intents:3.6.1")
androidTestImplementation("androidx.test:rules:1.6.1")

// Hilt (Dependency Injection)
implementation("com.google.dagger:hilt-android:2.51.1")
kapt("com.google.dagger:hilt-android-compiler:2.51.1")

implementation(libs.androidx.core.ktx)
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)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.espresso.contrib)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
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)
}

tasks.register("cucumber") {
dependsOn("assembleDebug", "compileDebugAndroidTestSources")
doLast {
javaexec {
mainClass.set("io.cucumber.core.cli.Main")
classpath = configurations.getByName("androidTestRuntimeClasspath").incoming.artifactView {}.files +
fileTree("src/androidTest/kotlin") +
fileTree("src/androidTest/resources")
args = listOf(
"--plugin", "pretty",
"--glue", "steps",
"src/androidTest/resources/features"
)
}
}
}

tasks.withType  {
doNotTrackState("Disabling state tracking for test tasks")
}

tasks.register("printConfigurations") {
doLast {
configurations.forEach { configuration ->
println("Configuration: ${configuration.name} (canBeResolved: ${configuration.isCanBeResolved})")
}
}
}

Код: Выделить всё

package com.kirabium.relayance.steps

import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.kirabium.relayance.ui.addCustomer.AddCustomerActivity
import io.cucumber.java.en.Given
import io.cucumber.java.en.When
import io.cucumber.java.en.Then
import org.junit.Rule

class AddCustomerSteps {

// Rule to launch the AddCustomerActivity before each test
@get:Rule
val activityRule = ActivityScenarioRule(AddCustomerActivity::class.java)

@Given("I am on the {string} screen")
fun iAmOnTheScreen(screenName: String) {
// Verify that the current screen is the "Add Customer" screen
Espresso.onView(ViewMatchers.withText(screenName))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
}

@When("I enter {string} in the {string} field")
fun iEnterInTheField(input: String, fieldName: String) {
// Find the field by its hint or label and enter the text
Espresso.onView(ViewMatchers.withHint(fieldName))
.perform(ViewActions.typeText(input))
}

@When("I click the {string} button")
fun iClickTheButton(buttonText: String) {
// Find the button by its text and click it
Espresso.onView(ViewMatchers.withText(buttonText))
.perform(ViewActions.click())
}

@Then("I should be redirected to the previous screen")
fun iShouldBeRedirectedToThePreviousScreen() {
// Verify that the current screen is no longer the "Add Customer" screen
Espresso.onView(ViewMatchers.withText("Add Customer"))
.check(ViewAssertions.doesNotExist())
}
}

Код: Выделить всё

package com.kirabium.relayance.test

import io.cucumber.junit.Cucumber
import io.cucumber.junit.CucumberOptions
import org.junit.runner.RunWith

@RunWith(Cucumber::class)
@CucumberOptions(
features = ["src/androidTest/resources/features"],
glue = ["com.kirabitm.relayance.steps"],
plugin = ["pretty"]
)
class RunCucumberTest

Код: Выделить всё

features = ["src/androidTest/resources/features"],
glue = ["com.kirabitm.relayance.steps"],
ничего из этого не работает.
Я ожидаю запуска теста и обнаруживаю единственный тест, который у меня есть в Cucumber.

Подробнее здесь: https://stackoverflow.com/questions/793 ... t-detected
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»