Android cucumber setup to run a sample feature file

This commit is contained in:
2023-02-25 15:32:17 +00:00
parent 7e2b034dd7
commit dd9beae7c0
6 changed files with 54 additions and 27 deletions

View File

@@ -14,7 +14,7 @@ android {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "io.cucumber.android.runner.CucumberAndroidJUnitRunner"
} }
buildTypes { buildTypes {
@@ -44,6 +44,9 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.activity:activity-ktx:1.6.1' implementation 'androidx.activity:activity-ktx:1.6.1'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation "io.cucumber:cucumber-android:${rootProject.ext.cucumberVersion}"
} }

View File

@@ -0,0 +1,5 @@
Feature: Sample feature file
@sample_test
Scenario: Successful login
Given I start the application

View File

@@ -1,24 +0,0 @@
package com.example.sumtest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.sumtest", appContext.packageName)
}
}

View File

@@ -0,0 +1,28 @@
package com.example.sumtest.steps
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.platform.app.InstrumentationRegistry
import com.example.sumtest.SumActivity
import io.cucumber.java.Before
import io.cucumber.java.en.Given
import org.junit.Assert
class SampleSteps {
private lateinit var mActivityScenarioRule: ActivityScenario<*>
@Before
fun setup() {
mActivityScenarioRule = ActivityScenario.launch(SumActivity::class.java)
}
@Given("I start the application")
fun I_start_the_application() {
mActivityScenarioRule.moveToState(Lifecycle.State.STARTED)
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
Assert.assertEquals("com.example.sumtest", appContext.packageName)
}
}

View File

@@ -0,0 +1,11 @@
package com.example.sumtest.test
import io.cucumber.junit.CucumberOptions
@CucumberOptions(
features = ["features"],
tags = ["@sample_test"],
glue = ["com.example.sumtest.steps"]
)
class CucumberRunner

View File

@@ -4,3 +4,7 @@ plugins {
id 'com.android.library' version '7.3.1' apply false id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
} }
ext {
cucumberVersion = "4.10.0"
}