Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a test example for Android Studio. #816

Merged
merged 5 commits into from
Jan 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/android/android-studio/Cukeulator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
72 changes: 72 additions & 0 deletions examples/android/android-studio/Cukeulator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## Cukeulator Example Test
This is the example test-project for the Cukeulator app for Android Studio 1.0.2.

### Setup
Features must be placed in `assets/features/`. Subdirectories are allowed.

The rest of the dependencies are added automatically in `app/build.gradle`.

The cucumber-android dependency is added as:

```
androidTestCompile 'info.cukes:cucumber-android:1.2.0@jar'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdzyuba this is due to the fact that there is an apklib and a jar file on maven central and jcenter.

@brasmusson / @aslakhellesoy do you know why the project was specified to be packaged as apklib? I think plain jar is sufficient.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SierraGolf No, I don't know why the cucumber-android module was specified to be packaged as an apklib. But as the apklib is an maven-android-plugin invented format, could it be that the apklib at the time that cucumber-android was originally created, it was the packaging that was promoted for an Android library project by the maven-android-plugin team?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brasmusson apklib does not make any sense to me, since we don't package anything to be used by an app including resources and other android specific things. I will make a pull request to change that.

```

Note, the `@jar` suffix is required in order to use the embedded jar file.

### Using gradle

To build the test apk:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case all the following steps are just about running the tests, why not simply say to run ./gradlew connectedCheck?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works also. I will update the readme.

Thank you!

  • Mykola

On Sat, Jan 3, 2015 at 7:19 AM, Sebastian Gröbler notifications@github.com
wrote:

In examples/android/android-studio/Cukeulator/README.md
#816 (diff)
:

@@ -0,0 +1,60 @@
+## Cukeulator Example Test
+This is the example test-project for the Cukeulator app for Android Studio (Beta) 0.8.14.
+
+### Setup
+Features must be placed in assets/features/. Subdirectories are allowed.
+
+The app/libs should contain cucumber-android-*.jar. Please build it following [cucumber-jvm/android]
+(https://github.com/cucumber/cucumber-jvm/tree/master/android) instructions and copy to app/libs folder.
+
+The rest of the dependencies are added automatically in app/build.gradle.
+
+
+### Using gradle
+
+To build the test apk:

in case all the following steps are just about running the tests, why not
simply say to run ./gradlew connectedCheck?


Reply to this email directly or view it on GitHub
https://github.com/cucumber/cucumber-jvm/pull/816/files#r22432101.


```
cd cucumber-jvm/examples/android/android-studio/Cukeulator

./gradlew --parallel :app:assembleDebugTest
```

The build generates an apk in app/build/outputs/apk/app-debug.apk.

To install the apk on a device:

```
adb install -r app/build/outputs/apk/app-debug.apk
```

To verify that the test is installed, run:

```
adb shell pm list instrumentation
```

The command output should display;

```
instrumentation:cukeulator.android.example.cucumber.cukeulator.test/cucumber.api.android.CucumberInstrumentation (target=cukeulator.android.example.cucumber.cukeulator)
```

To run the test:

```
cd cucumber-jvm/examples/android/android-studio/Cukeulator;
./gradlew connectedCheck
```

As an alternative option, the test can be run with adb:

```
adb shell am instrument -w cukeulator.android.example.cucumber.cukeulator.test/cucumber.api.android.CucumberInstrumentation
```

### Using an Android Studio IDE
1. Import the example to Android Studio: `File > Import Project`.
2. Make sure you have the cucumber-android jar dependencies in `app/libs/`.
3. Create a test run confiruation:
1. Run > Edit Configurations
2. Click `+` button and select Android Tests
3. Specify test name: `CalculatorTest`
4. Select module: `app`
5. Enter a Specific instrumentation runner: `cucumber.api.android.CucumberInstrumentation`
6. Click Ok

### Output
Filter for the logcat tag `cucumber-android` in [DDMS](https://developer.android.com/tools/debugging/ddms.html).
1 change: 1 addition & 0 deletions examples/android/android-studio/Cukeulator/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
41 changes: 41 additions & 0 deletions examples/android/android-studio/Cukeulator/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.1"

defaultConfig {
applicationId "cukeulator.android.example.cucumber.cukeulator"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"

testApplicationId "cukeulator.android.example.cucumber.cukeulator.test"
testInstrumentationRunner "cucumber.api.android.CucumberInstrumentation"
}
sourceSets {
androidTest {
assets.srcDirs = ['src/androidTest/assets']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'info.cukes:cucumber-android:1.2.0@jar'
androidTestCompile 'info.cukes:cucumber-core:1.2.0'
androidTestCompile 'info.cukes:cucumber-html:0.2.3'
androidTestCompile 'info.cukes:cucumber-java:1.2.0'
androidTestCompile 'info.cukes:cucumber-junit:1.2.0'
androidTestCompile 'info.cukes:cucumber-jvm-deps:1.0.3'
androidTestCompile 'info.cukes:cucumber-picocontainer:1.2.0'
androidTestCompile 'info.cukes:gherkin:2.12.2'
androidTestCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions examples/android/android-studio/Cukeulator/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/mdzyuba/Code/android/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Calculate a result
Perform an arithmetic operation on two numbers using a mathematical operator
"""The purpose of this feature is to illustrate how existing step-definitions
can be efficiently reused."""

Scenario Outline: Enter a digit, an operator and another digit
Given I have a CalculatorActivity
When I press <num1>
And I press <op>
And I press <num2>
And I press =
Then I should see <result> on the display

Examples:
| num1 | num2 | op | result |
| 9 | 8 | + | 17.0 |
| 7 | 6 | – | 1.0 |
| 5 | 4 | x | 20.0 |
| 3 | 2 | / | 1.5 |
| 1 | 0 | / | Infinity |
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Add two numbers
Calculate the sum of two numbers which consist of one or more digits

Scenario Outline: Enter one digit per number and press =
Given I have a CalculatorActivity
When I press <num1>
And I press +
And I press <num2>
And I press =
Then I should see <sum> on the display

Examples:
| num1 | num2 | sum |
| 0 | 0 | 0.0 |
| 0 | 1 | 1.0 |
| 1 | 1 | 2.0 |

Scenario Outline: Enter two digits per number and press =
Given I have a CalculatorActivity
When I press <num1>
When I press <num2>
And I press +
And I press <num3>
And I press <num4>
And I press =
Then I should see <sum> on the display

Examples:
| num1 | num2 | num3 | num4 | sum |
| 0 | 0 | 2 | 0 | 20.0 |
| 9 | 8 | 7 | 6 | 174.0 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Divide two numbers
Calculate the quotient of two numbers which consist of one or more digits

Scenario Outline: Enter one digit per number and press =
Given I have a CalculatorActivity
When I press <num1>
And I press /
And I press <num2>
And I press =
Then I should see <quotient> on the display

Examples:
| num1 | num2 | quotient |
| 0 | 0 | NaN |
| 1 | 0 | Infinity |
| 1 | 2 | 0.5 |

Scenario Outline: Enter two digits per number and press =
Given I have a CalculatorActivity
When I press <num1>
When I press <num2>
And I press /
And I press <num3>
And I press <num4>
And I press =
Then I should see <quotient> on the display

Examples:
| num1 | num2 | num3 | num4 | quotient |
| 2 | 2 | 2 | 2 | 1.0 |
| 2 | 0 | 1 | 0 | 2.0 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Multiply two numbers
Calculate the product of two numbers which consist of one or more digits

Scenario Outline: Enter one digit per number and press =
Given I have a CalculatorActivity
When I press <num1>
And I press x
And I press <num2>
And I press =
Then I should see <product> on the display

Examples:
| num1 | num2 | product |
| 0 | 0 | 0.0 |
| 0 | 1 | 0.0 |
| 1 | 2 | 2.0 |

Scenario Outline: Enter two digits per number and press =
Given I have a CalculatorActivity
When I press <num1>
When I press <num2>
And I press x
And I press <num3>
And I press <num4>
And I press =
Then I should see <product> on the display

Examples:
| num1 | num2 | num3 | num4 | product |
| 2 | 2 | 2 | 2 | 484.0 |
| 2 | 0 | 1 | 0 | 200.0 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Subtract two numbers
Calculate the difference of two numbers which consist of one or more digits

Scenario Outline: Enter one digit per number and press =
Given I have a CalculatorActivity
When I press <num1>
And I press –
And I press <num2>
And I press =
Then I should see <delta> on the display

Examples:
| num1 | num2 | delta |
| 0 | 0 | 0.0 |
| 0 | 1 | -1.0 |
| 1 | 2 | -1.0 |

Scenario Outline: Enter two digits per number and press =
Given I have a CalculatorActivity
When I press <num1>
When I press <num2>
And I press –
And I press <num3>
And I press <num4>
And I press =
Then I should see <delta> on the display

Examples:
| num1 | num2 | num3 | num4 | delta |
| 2 | 2 | 2 | 2 | 0.0 |
| 2 | 0 | 1 | 0 | 10.0 |
Loading