{"action":"created","issue":{"url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/311","repository_url":"https://api.github.com/repos/Polidea/RxAndroidBle","labels_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/311/labels{/name}","comments_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/311/comments","events_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/311/events","html_url":"https://github.com/Polidea/RxAndroidBle/issues/311","id":272345731,"number":311,"title":"Remove need to use RoboElectric for creating tests using `MockRxAndroidBle`","user":{"login":"streetsofboston","id":3649463,"avatar_url":"https://avatars0.githubusercontent.com/u/3649463?v=4","gravatar_id":"","url":"https://api.github.com/users/streetsofboston","html_url":"https://github.com/streetsofboston","followers_url":"https://api.github.com/users/streetsofboston/followers","following_url":"https://api.github.com/users/streetsofboston/following{/other_user}","gists_url":"https://api.github.com/users/streetsofboston/gists{/gist_id}","starred_url":"https://api.github.com/users/streetsofboston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/streetsofboston/subscriptions","organizations_url":"https://api.github.com/users/streetsofboston/orgs","repos_url":"https://api.github.com/users/streetsofboston/repos","events_url":"https://api.github.com/users/streetsofboston/events{/privacy}","received_events_url":"https://api.github.com/users/streetsofboston/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-11-08T20:54:17Z","updated_at":"2017-11-13T12:37:44Z","closed_at":null,"author_association":"NONE","body":"### Summary\r\nRemove the _need_ for RoboElectric when writing tests using `MockRxAndroidBle`\r\nRoboElectric causes the startup of tests to be quite slow. Removing the dependency\r\non RoboElectric and being able to use only Mockito, for example, would improve the\r\nprocess of TDD because tests can be run faster.\r\n\r\n### Library version\r\n`1.4.1`\r\n\r\n#### Issue found in `MockRxAndroidBle` implementation\r\nWhen trying to run tests that use the `MockRxAndroidBle` class without RoboElectric, they fail because the test-code creates instances of classes from the Android SDK. \r\n\r\nOur test-suite reports failures of usages of these classes:\r\n`BluetoothGattService`\r\n`BluetoothGattCharacteristic`\r\n`BluetoothGattDescriptor`\r\n\r\nUsing PowerMock and using it to create mock-instances of these three classes makes these failures go away and the tests in our own project run fine! \r\n\r\nHowever, using PowerMock requires this annotation at the head of the test-suite-class:\r\n(snippet in Kotlin)\r\n```\r\n@PrepareForTest(\r\n        value = [(RxBleClientMock.CharacteristicsBuilder::class), (RxBleClientMock.DeviceBuilder::class)],\r\n        fullyQualifiedNames = [\"com.polidea.rxandroidble.mockrxandroidble.RxBleConnectionMock\\$21\"]\r\n)\r\n```\r\nNeedless to say, this annotation is given knowledge of internal and private implementation details of `MockRxAndroidBle`. There's no guarantee that a future version of `MockRxAndroidBle' won't break this annotation configuration.....\r\n\r\n#### Request for change in `MockRxAndroidBle` implementation.\r\nCurrently (version 1.4.1), the `RxBleClientMock.CharacteristicsBuilder`, `RxBleClientMock.DeviceBuilder` and `RxBleConnectionMock$21` (anonymous class) create instance of `BluetoothGattService`, `BluetoothGattCharacteristic` or `BluetoothGattDescriptor`directly. \r\n\r\n1. Either a factory pattern could be used to create these classes allowing users (writers of unit-tests) to inject mocked versions of these instances.\r\n2. Or the implementation of `MockRxAndroidBle` could create mocked version instead (and thereby requiring only Mockito).\r\n"},"comment":{"url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/comments/343906493","html_url":"https://github.com/Polidea/RxAndroidBle/issues/311#issuecomment-343906493","issue_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/311","id":343906493,"user":{"login":"dariuszseweryn","id":1412475,"avatar_url":"https://avatars0.githubusercontent.com/u/1412475?v=4","gravatar_id":"","url":"https://api.github.com/users/dariuszseweryn","html_url":"https://github.com/dariuszseweryn","followers_url":"https://api.github.com/users/dariuszseweryn/followers","following_url":"https://api.github.com/users/dariuszseweryn/following{/other_user}","gists_url":"https://api.github.com/users/dariuszseweryn/gists{/gist_id}","starred_url":"https://api.github.com/users/dariuszseweryn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dariuszseweryn/subscriptions","organizations_url":"https://api.github.com/users/dariuszseweryn/orgs","repos_url":"https://api.github.com/users/dariuszseweryn/repos","events_url":"https://api.github.com/users/dariuszseweryn/events{/privacy}","received_events_url":"https://api.github.com/users/dariuszseweryn/received_events","type":"User","site_admin":false},"created_at":"2017-11-13T12:37:44Z","updated_at":"2017-11-13T12:37:44Z","author_association":"COLLABORATOR","body":"This issue is a part of #213 and #239. The new API aims for fully wrapping the Android OS objects.\r\n\r\nI am also thinking if there is really a need for the `MockClient` in the unit tests. It should be possible to inject your own mock implementations of `RxBleDevice` and `RxBleConnection`. As @mzgreen has mentioned above the `MockClient` was created as a quick drop-in replacement for the library if the peripheral you want to use is not available but still you would like to use mock it in the application.\r\n\r\nIt could be put up for a discussion if we should remove this part of `Readme.md`:\r\n```\r\n## Unit testing\r\nUsing RxAndroidBle enables you to unit test your application easily. For examples how to use mocking head to [MockRxAndroidBle](https://github.com/Polidea/RxAndroidBle/tree/master/mockrxandroidble).\r\n\r\nNote: Using MockRxAndroidBle in unit tests needs [Robolectric](https://github.com/robolectric/robolectric).\r\n```"}}
{"actor":{"display_login":"dariuszseweryn"}}