{"action":"created","issue":{"url":"https://api.github.com/repos/cucumber/cucumber-jvm/issues/894","repository_url":"https://api.github.com/repos/cucumber/cucumber-jvm","labels_url":"https://api.github.com/repos/cucumber/cucumber-jvm/issues/894/labels{/name}","comments_url":"https://api.github.com/repos/cucumber/cucumber-jvm/issues/894/comments","events_url":"https://api.github.com/repos/cucumber/cucumber-jvm/issues/894/events","html_url":"https://github.com/cucumber/cucumber-jvm/issues/894","id":99008718,"number":894,"title":"[Android] Support Testing with JUnit4 Style Rules","user":{"login":"mikeholler","id":1164112,"avatar_url":"https://avatars.githubusercontent.com/u/1164112?v=3","gravatar_id":"","url":"https://api.github.com/users/mikeholler","html_url":"https://github.com/mikeholler","followers_url":"https://api.github.com/users/mikeholler/followers","following_url":"https://api.github.com/users/mikeholler/following{/other_user}","gists_url":"https://api.github.com/users/mikeholler/gists{/gist_id}","starred_url":"https://api.github.com/users/mikeholler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikeholler/subscriptions","organizations_url":"https://api.github.com/users/mikeholler/orgs","repos_url":"https://api.github.com/users/mikeholler/repos","events_url":"https://api.github.com/users/mikeholler/events{/privacy}","received_events_url":"https://api.github.com/users/mikeholler/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cucumber/cucumber-jvm/labels/Android","name":"Android","color":"fef2c0"},{"url":"https://api.github.com/repos/cucumber/cucumber-jvm/labels/Won't%20Fix","name":"Won't Fix","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2015-08-04T16:35:16Z","updated_at":"2016-09-01T15:04:29Z","closed_at":"2016-09-01T15:04:29Z","body":"I converted the Android example ``CalculatorActivitySteps`` from this:\r\n\r\n```java\r\npublic class CalculatorActivitySteps extends ActivityInstrumentationTestCase2<CalculatorActivity> {\r\n\r\n    public CalculatorActivitySteps(SomeDependency dependency) {\r\n        super(CalculatorActivity.class);\r\n        assertNotNull(dependency);\r\n    }\r\n\r\n    @Given(\"^I have a CalculatorActivity$\")\r\n    public void I_have_a_CalculatorActivity() {\r\n        assertNotNull(getActivity());\r\n    }\r\n\r\n    @When(\"^I press (\\\\d)$\")\r\n    public void I_press_d(final int d) {\r\n        switch (d) {\r\n            case 0:\r\n                onView(withId(R.id.btn_d_0)).perform(click());\r\n                break;\r\n            case 1:\r\n                onView(withId(R.id.btn_d_1)).perform(click());\r\n                break;\r\n            case 2:\r\n                onView(withId(R.id.btn_d_2)).perform(click());\r\n                break;\r\n            case 3:\r\n                onView(withId(R.id.btn_d_3)).perform(click());\r\n                break;\r\n            case 4:\r\n                onView(withId(R.id.btn_d_4)).perform(click());\r\n                break;\r\n            case 5:\r\n                onView(withId(R.id.btn_d_5)).perform(click());\r\n                break;\r\n            case 6:\r\n                onView(withId(R.id.btn_d_6)).perform(click());\r\n                break;\r\n            case 7:\r\n                onView(withId(R.id.btn_d_7)).perform(click());\r\n                break;\r\n            case 8:\r\n                onView(withId(R.id.btn_d_8)).perform(click());\r\n                break;\r\n            case 9:\r\n                onView(withId(R.id.btn_d_9)).perform(click());\r\n                break;\r\n        }\r\n    }\r\n\r\n    @When(\"^I press ([+–x\\\\/=])$\")\r\n    public void I_press_op(final char op) {\r\n        switch (op) {\r\n            case '+':\r\n                onView(withId(R.id.btn_op_add)).perform(click());\r\n                break;\r\n            case '–':\r\n                onView(withId(R.id.btn_op_subtract)).perform(click());\r\n                break;\r\n            case 'x':\r\n                onView(withId(R.id.btn_op_multiply)).perform(click());\r\n                break;\r\n            case '/':\r\n                onView(withId(R.id.btn_op_divide)).perform(click());\r\n                break;\r\n            case '=':\r\n                onView(withId(R.id.btn_op_equals)).perform(click());\r\n                break;\r\n        }\r\n    }\r\n\r\n    @Then(\"^I should see (\\\\S+) on the display$\")\r\n    public void I_should_see_s_on_the_display(final String s) {\r\n        onView(withId(R.id.txt_calc_display)).check(matches(withText(s)));\r\n    }\r\n}\r\n```\r\n\r\nTo this:\r\n\r\n```java\r\npublic class CalculatorActivitySteps {\r\n\r\n    @Rule\r\n    private ActivityTestRule<CalculatorActivity> mActivityRule =\r\n            new ActivityTestRule<>(CalculatorActivity.class);\r\n\r\n    @Given(\"^I have a CalculatorActivity$\")\r\n    public void I_have_a_CalculatorActivity() {\r\n        mActivityRule.launchActivity(new Intent());\r\n    }\r\n\r\n    @When(\"^I press (\\\\d)$\")\r\n    public void I_press_d(final int d) {\r\n        switch (d) {\r\n            case 0:\r\n                onView(withId(R.id.btn_d_0)).perform(click());\r\n                break;\r\n            case 1:\r\n                onView(withId(R.id.btn_d_1)).perform(click());\r\n                break;\r\n            case 2:\r\n                onView(withId(R.id.btn_d_2)).perform(click());\r\n                break;\r\n            case 3:\r\n                onView(withId(R.id.btn_d_3)).perform(click());\r\n                break;\r\n            case 4:\r\n                onView(withId(R.id.btn_d_4)).perform(click());\r\n                break;\r\n            case 5:\r\n                onView(withId(R.id.btn_d_5)).perform(click());\r\n                break;\r\n            case 6:\r\n                onView(withId(R.id.btn_d_6)).perform(click());\r\n                break;\r\n            case 7:\r\n                onView(withId(R.id.btn_d_7)).perform(click());\r\n                break;\r\n            case 8:\r\n                onView(withId(R.id.btn_d_8)).perform(click());\r\n                break;\r\n            case 9:\r\n                onView(withId(R.id.btn_d_9)).perform(click());\r\n                break;\r\n        }\r\n    }\r\n\r\n    @When(\"^I press ([+–x\\\\/=])$\")\r\n    public void I_press_op(final char op) {\r\n        switch (op) {\r\n            case '+':\r\n                onView(withId(R.id.btn_op_add)).perform(click());\r\n                break;\r\n            case '–':\r\n                onView(withId(R.id.btn_op_subtract)).perform(click());\r\n                break;\r\n            case 'x':\r\n                onView(withId(R.id.btn_op_multiply)).perform(click());\r\n                break;\r\n            case '/':\r\n                onView(withId(R.id.btn_op_divide)).perform(click());\r\n                break;\r\n            case '=':\r\n                onView(withId(R.id.btn_op_equals)).perform(click());\r\n                break;\r\n        }\r\n    }\r\n\r\n    @Then(\"^I should see (\\\\S+) on the display$\")\r\n    public void I_should_see_s_on_the_display(final String s) {\r\n        onView(withId(R.id.txt_calc_display)).check(matches(withText(s)));\r\n    }\r\n}\r\n```\r\n\r\nWhen using the ``@Rule``, the activity would not shutdown after the first test.\r\n"},"comment":{"url":"https://api.github.com/repos/cucumber/cucumber-jvm/issues/comments/244108081","html_url":"https://github.com/cucumber/cucumber-jvm/issues/894#issuecomment-244108081","issue_url":"https://api.github.com/repos/cucumber/cucumber-jvm/issues/894","id":244108081,"user":{"login":"sebrose","id":2204142,"avatar_url":"https://avatars.githubusercontent.com/u/2204142?v=3","gravatar_id":"","url":"https://api.github.com/users/sebrose","html_url":"https://github.com/sebrose","followers_url":"https://api.github.com/users/sebrose/followers","following_url":"https://api.github.com/users/sebrose/following{/other_user}","gists_url":"https://api.github.com/users/sebrose/gists{/gist_id}","starred_url":"https://api.github.com/users/sebrose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebrose/subscriptions","organizations_url":"https://api.github.com/users/sebrose/orgs","repos_url":"https://api.github.com/users/sebrose/repos","events_url":"https://api.github.com/users/sebrose/events{/privacy}","received_events_url":"https://api.github.com/users/sebrose/received_events","type":"User","site_admin":false},"created_at":"2016-09-01T15:04:29Z","updated_at":"2016-09-01T15:04:29Z","body":"One way of running Cucumber is by using JUnit, but there are others, so we would not want to couple Cucumber & JUnit by sharing a JUnit annotation."}}
{"actor":{"display_login":"sebrose"}}