Mocking web server for development - android

I'm curious if anyone uses a tool like MockWebServer for general development?
I've used MockWebServer to run instrumentation tests against. In a testing situation it's very easy to use because you can enqueue the response you want per test method.
I feel it could be useful for general development (not running an instrumentation test) where the endpoint hasn't been developed yet but you still want to start client side development and don't necessarily want to have a TDD approach where you run an instrumentation test every time you want to try out the feature you're developing.
Does anyone have experience using MockWebServer (or a similar tool) in this way? Are there any pitfalls to it?

Related

Does Android Studio provide a way to test interactions between devices?

While developing an app I more and more stumble upon the fact that I need to run interaction tests where two emulators are running the app to ensure the entire integration is working by testing the interaction between those (and not mock one of the devices)
During research on the topic (which is quite hard to search for because I do not want to run the same tests on multiple devices) I found a couple of solutions, however none of them seem to integrate very well into an Android Studio workflow. Some tools I've found:
UiAutomator
UI/Application Exerciser Monkey
Appmium
Some blend of adb, ruby, python etc.
Some projects on github
My expectation may be off but is there no framework or tool with a similar level of integration like running an instrumented tests that allows me to connect to several devices and perform interactions on them together?
Some of those approaches above require out-of-the-tool tinkering with adb or require a lot of environment to be set up.
Good answer to this question here:
https://stackoverflow.com/a/49647422/14338677
In short:
1.Create communication proxy that will be between sender and receiver
2.Add build type autoresponder, and communication proxy code get empty if (!BuildConfig.AUTORESPONDER)
3.Install autoresponder app to emulator or device when you will be testing
4.Run another test app with Espresso that can communicate with autoresponder app
5.Use Thread.sleep(...) to wait response of autoresponder app

testing mobile web app on iOS and Android

I need to test a mobile web app on both iOS(Safari) and Android(Chrome). Do I need to create separate scripts depending on the OS or can logic be inserted in the same script (like getting OS name) and then executing the relevant flow.
Another aspect is that AWS device farm will be used for the testing. Hence what is best practice for writing the above-mentioned script
Assuming both apps share the same UI it is certainly possible to use a single Appium test to test both Android and iOS; however, this can be tricky at times. Here is a good blog post discussing the issue.
cross-platform-testing
Scott

Best practices for Android Unit Testing?

I am developing a mobile android app. What are the most common libraries/frameworks used for Android unit testing? I feel that most of the business logic, database testing, Web services testing can all be done using JUnit.
However, what's the best approach for testing UI, the UI workflow, etc? For example, how can we test if the Android app launches a web browser successfully? Or how can we confirm if buttons, certain things are pressed successfully? Or if images are loaded successfully?
I use JUnit for unit testing and Robolectric for instrumentation tests.
This article shows you a Hello World example with Robolectric
In recent times, I have been researching about integration testing in Android using Arquillian Droidium.
If you want to test some code that consumes a REST API, you can mock it with WireMock. With this library, you can mock REST APIs by code or even deploy a mock HTTP server in your own machine and set up your own mocked mappings.
For REST API mocks, I also recommend you to use Mockable.io.
2017 answer
The Android documentation has a topical series called Best Practices for Testing. I would start there.
Local Unit Tests and Instrumented Tests are set up by default when you start a new project. The general advice given is to use the local unit tests whenever possible. Sometimes this requires mocking an object that uses the Android API. The documentation recommends using Mockito in these cases. When UI tests (instrumented tests) need to be done, Android provides the Espresso framework. There are also other tools available, like the Exerciser Monkey (for stress testing) and UI Automator (for testing multiple app interaction).
Example
See this answer for how to get started with tests in Android Studio.
There is a guide for automated user interface testing on the Android Developers Website. I haven't tried it but it looks like what you've been looking for.

Automatic Testing for Cordova/Phonegap Webview on Android

I'm currently looking for a solution to test Android Apps automatically, native Android apps as well as hybrid Cordova/Phonegap apps.
The UI Automator from Google looks pretty fine, but can not deal with WebViews, which makes it unusable for me.
Then I found the promising automation framework Appium based on Selenium, which should also be able to deal with hybrid apps, but I couldn't get it to work with WebViews, it seems to not be implemented fully yet, as also several posts prove.
After trying Appium I found a hint for Selendroid, that also should work for hybrid apps, but it seems pretty much buggy and keeps crashing my whole computer all the time.
So, does anyone here know a working solution for testing Android Apps with WebViews? I'm working on Windows 7. Thanks a lot in advance for any help.
In first case we need to know what kind of tests you like to drive. I think you like to run functional tests on the UI? Thats what i can think about after reading your question.
So lets split this by the given environment:
native iOS
unit tests -> do it in xCode. http://www.apple.com
functionality tests -> http://appium.io/
native Android
unit tests -> JUnit, http://developer.android.com/tools/testing/testing_android.html
functionality tests -> http://selendroid.io/
native Web like phonegap/cordova Apps
unit tests -> jsUnit, http://jsunit.berlios.de/
QA Testing and Checkstyle -> jsHint/jsLint, http://www.jshint.com/ & http://www.jslint.com/
functionality tests -> http://docs.seleniumhq.org/ & https://npmjs.org/package/ripple-
functionality tests (E2E) -> https://angular.github.io/protractor/#/ or https://github.com/jasmine/jasmine
Here is a article about JavaScript QA / QS
native X - The out of the Box solution for all Platforms
Here we are. There is none atm. But .. footage is that one here:
Gappium based on appium uses json for writing your tests. As i get the thread right, it was testet with Web/iOS for this moment. Android/Win seems not be integrated for this moment:
https://github.com/appium/io.appium.gappium.sampleapp
Note for phonegap & apache cordova functional tests:
Its possible to use ripple and selenium for testing hybrid apps. Keep in mind that some native function/plugins (hehe native functions on hybrid apps ... =) cant be tested or need to be mocked on a unknown way. Thats the footage for this moment.
Maybe usefull for you Continous Integration Server:
https://github.com/linslin/PHPUnit-selenium-HTMLGallery
Generally, testing hybrid apps is quite a challenge with API-based approaches. It can be done, but typically you need to integrate the UI technologies (e.g. WebView, Native, OpenGL, ...) with several APIs or some kind of wrapper (like Selendroid).
Here at TestObject (I'm one of the co-founders) we've created an Image-based UI testing approach specifically for cases like hybrid apps, interaction between apps, and so forth. This black-box approach is solely based on capturing the screen - we don't care what happens underneath.
Feel free to give it a try (http://testobject.com/) with your hybrid Cordova/Phonegap app and let me know how it worked out in comparison to UI Automator, Selendroid, Appium. Let us know if you stumble over any issues.
I faced this challenge with our own Cordova app ( sourceforge.net/p/ustadmobil/codehtml5cordova/ci/master/tree/ ) ; and I needed a way to integrate this with Jenkins CI. We have Cordova specific code (e.g. filesystem access) so just using PhantomJS and Grunt is not an option.
Essentially what I did was to launch the app with the test page as index.html in the emulator, run an http server, and then have the test page pass the results back using AJAX.
Script launches an emulator with the package
$ /opt/adt/sdk/tools/emulator-x86 -avd $AVDNAME -qemu -m 2047 &
$ EMULATEPID=$!
$ adb wait-for-device #wait for device to start
$ adb shell input keyevent 82 #unlock screen
Make a test page using qunit, which when finished will communicate the test results with an AJAX call.
Make a basic nodejs server script that will listen for that ajax call and save the results to a file. A bash script can then read that file and determine if the tests passed or failed : see http://sourceforge.net/p/ustadmobil/codehtml5cordova/ci/master/tree/setup/node-qunit-server/node-qunit-server.js
In the build script wait for the result file to come, then kill the emulator and the NodeJS server - see http://sourceforge.net/p/ustadmobil/codehtml5cordova/ci/master/tree/setup/android/unit-test-setup-android.sh
Also worth noting: this approach works for the cross platform nature of Cordova: it should be possible to take the same approach running iOS, Windows Phone emulators etc (I also use this test method against our NodeWebKit desktop version which shares most of the code).
Hope this helps,
-Mike

Android Test Automation

How can i automate Android Apis for better quality ? How can i test the android applications to get a better quality of this software..?
I would recommend you checkout Robolectric for testing Android apps.
Use Robotium, its a good tool to use for Android Automation
http://www.robotium.org/
Try robotium, i am using it, Its very easy for writing your Functional Test Cases and can be tested in all android Devices.
Espresso is the best option coming forward to automate the android API's. Google has developed this testing kit for developers to write the unit test cases. Here's the Google's home page for espresso
https://code.google.com/p/android-test-kit/wiki/EspressoStartGuide
Google has also implemented the sample test cases which help to learn espresso faster. Main advantage of espresso is its speed of execution and its work asynchronously meaning we are not explicitly required to write wait for actions in espresso. Developer should only perform action, waiting time taken care by espresso.
Here's link which gives start to espresso in easy to understand way:
http://www.stevenmarkford.com/android-ui-testing-with-espresso-basics-tutorial/
I would suggest you to use Seetest.
This is also an automation tool independent of any platform. You can run the same test script across all the platforms like Android, IPhone, Windows Phone using this tool. Moreover it has a plugin for existing test frameworks like QTP, Testcomplete etc. Here is the link to download the trial version of the same.
http://experitest.com/support/download-2/
I would suggest Webdriver/ selenium 2.0 android driver if you are looking for open source. its good and robust as well
Try bot-bot. Its a functional automation tool built over Robotium/Nativedriver. It have recording feature which helps in easy element identification and writing test-cases.
It uses "Ant" for build and running the tests. This helps in integration with continuous integration tools.
At the end of your test execution it generates emailable html reports with pass-fail status.
If you have a spare Raspberry-Pi, you can also use that to speedup your test :) , much better than running on Emulator:
Raspberry-PI for Android Test Automation

Categories

Resources