mirror of
https://github.com/hmalik144/sumtest.git
synced 2025-12-10 03:05:27 +00:00
Android cucumber setup to run a sample feature file
This commit is contained in:
@@ -14,7 +14,7 @@ android {
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
testInstrumentationRunner "io.cucumber.android.runner.CucumberAndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
@@ -44,6 +44,9 @@ dependencies {
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
||||
implementation 'androidx.activity:activity-ktx:1.6.1'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
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}"
|
||||
}
|
||||
5
app/src/androidTest/assets/features/sample.feature
Normal file
5
app/src/androidTest/assets/features/sample.feature
Normal file
@@ -0,0 +1,5 @@
|
||||
Feature: Sample feature file
|
||||
|
||||
@sample_test
|
||||
Scenario: Successful login
|
||||
Given I start the application
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -4,3 +4,7 @@ plugins {
|
||||
id 'com.android.library' version '7.3.1' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
|
||||
}
|
||||
|
||||
ext {
|
||||
cucumberVersion = "4.10.0"
|
||||
}
|
||||
Reference in New Issue
Block a user