I have been using robotium to test my android application.Testing was successful but i want to know that is there any way to view test results in a separate file.
I have had good luck just running the robotium tests as regular Android JUnit tests, and then using the standard mechanism to get back the test results, namely the ant task fetch-test-report. To do this I used the build.xml file create by android through the tooling. See documentation for developing in other IDEs for detailed instructions on setting that up. Good luck!
XML report generation is quite simple when we are using Eclipse IDE
Steps to be followed
Run the Junit test as usual in eclipse Run As->Android Junit Test.
Once the test run is completed you will be indicated with the status in the status bar provided by the IDE.
When you click on the Test Run History Icon which is available in the Junit view of eclipse IDE you will find the Export option through which you can you can export the XML format test.
If you have and problems in finding the icon please watch the below image.
I use approach with logcat and android class Log.'severity'(tag, msg) ('severity' can be i-info, d-debug, w-warn, e-error, v-verbose), here is an example of clicking button myView:
String viewName = solo.getString(R.string.myViewName);
try {
solo.clickOnView((View) solo.getView(R.id.myView));
Log.i("Passed", viewName + " works correctly.");
} catch (Exception e) {
Log.e("Error", viewName + " doesn't work.");
}
Using filters you can filter output by tags and selecting all lines save it in .txt file. All these you can do automatically by writing simple script which will redirect output to file from InstrumentationTestRunner for you.
see also pages: Log class, logcat
In my case, I user spoon to generate test html reports. https://github.com/square/spoon
You can follow the way of your choice because it is not pure junit code:
1-XML based test execution report using any xml writing/parsing apis
2-logcat based test execution report using logs for example if you are using Eclipse IDE
3-customized report writing to your device under test, for this you will need apis to write to device
These are three ways out of several available as per your requirements and IDE.
You can use the PolideainstrumentationtestRunner, it allows you to specify exactly where you want to store the test result. (add option junitXmlOutput true and junitOutputDirectory yourPath)
http://code.google.com/p/the-missing-android-xml-junit-test-runner/
I hope it will help.
Related
I'm struggling with instrumental ui test of a PlaceAutocomplete API, provided by Google.
What I'm trying to test is ability to open AutoComplete Activity (fired with proper button), enter some text, pick result from given list and check if picked position is listed on the recyclerview.
I'm trying to target this EditText below :(
with:
onView(withClassName(equalTo(EditText.class.getName())))
.inRoot(withDecorView(not(is(homeActivityActivityTestRule.getActivity().getWindow().getDecorView()))))
.perform(typeTextIntoFocusedView("kotek"), closeSoftKeyboard());
And other variations, like withText "Szukaj" or with com.google.android.gms.R.id :) without luck.
Help will be appreciated! Thank You!
This view is auto-generated by Google Api.
If it's true, sorry I haven't any experience with Places API, it would mean that Espresso is unable to find this view.
Solution: Espresso Test Recorder
You can install the latest Android Studio 2.2-RC2 (don't remove the previous) from: http://tools.android.com/download/studio/builds/2-2-rc to check brand new Espresso Test Recorder (check: http://tools.android.com/tech-docs/test-recorder) and try to get this view by click on this to generate code, but I said this might not help.
Solution: Espresso with uiatomator
My doubts about it come from Espresso framework limitation - it depends on actual context of app, it means that it may not recognize intents, genereated code or notifications.
Try to use typical instrumentation framework like Google's uiatomator. There's no problem to use it along with Espresso UI testing framework.
Read: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html
More info you would find here: http://google.github.io/android-testing-support-%20/docs/uiautomator/
Solution: Espresso with Robotium or Robotium Test Recorder
If you find uiatomator a pretty hard to learn you can also use another instrumentation test framework called Robotium, which has clean and conchise syntax with some powerfull functions like taking screenshots.
It can work along with Espresso. Check last paragraph of this article: https://github.com/codepath/android_guides/wiki/UI-Testing-with-Robotium
It also has its own recorder: http://robotium.com/products/robotium-recorder. Try it for free, but I doubt that you would find it useful, as Robotium code is really simple to learn.
Hope it will help
Install Android studio 2.2 Beta, Try the Espresso test recorder. It will automatically generate an Espresso test case for you.
Try with this one :-
Espresso.onView(ViewMatchers.withId(R.id.places_autocomplete_edit_text))
.perform(ViewActions.typeText("<ADDRESS>"))
Thread.sleep(3000);
onView(withText("<ADDRESS FROM SUGESSION>"))
.inRoot(withDecorView(Matchers.not(activityTestRule.activity.window.decorView)))
.perform(click())
Tested with :- Android Studio:3.5.2 | espresso-core:3.1.1 | places:1.1.0
Autocompleater component seems to be not accessible using espresso, one solution is to send typing then clicking through a shell
getInstrumentation().getUiAutomation().executeShellCommand("input text n")
sleep(2000)
getInstrumentation().getUiAutomation().executeShellCommand("input tap " + Math.round(width / 2f) + " " + Math.round(height / 4f))
Firstly I want to make a confession. I've never written a test before. I've been a programmer for more than 10 years, and never once I found the need to write a proper test (or whatever it is called) since mostly I write codes that (I think) can be easily tested manually.
Now I'm writing a pretty complex android app, and this manual testing I'm doing to make sure every functions and classes runs as intended slows me down miserably. So now I'm kinda searching in the dark on how to make my codes test-compatible (is there such a thing?) and where should I start.
I'm using the latest Android Studio (1.2 Beta 3). I found that under 'src' folder, there's an 'androidTest' folder, which (few folders beneath it) contains a file, ApplicationTest.java. Here's the content of ApplicationTest.java
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
Ok now back to my app. I want to test the class AnalyzerOffline.java (located under main>java>com.code.imin.app) that I've written, because it has pretty complex and large codes going around there. So how should I start? I tried reading http://developer.android.com/tools/testing/testing_android.html , http://rexstjohn.com/unit-testing-with-android-studio/ etc but I still don't know where to start - I feel like I'm missing something here, or maybe somehow my mindset of writing test or the whole idea of it are wrong.
So can please someone show me some light here?
I am using Monkey tool testing
Step 1:
open the android studio terminal(Tools-> open terminal)
Step 2:
In order to use monkey , open up a command prompt and just naviagte to the following directory.
export PATH=$PATH:/home/adt-bundle-linux-x86-20140702/sdk/platform-tools
Step 3:
add this monkey command into terminal and press enter..
see the magic in your emulator.
adb shell monkey -p com.example.yourpackage -v 500
500- it is the frequency count or the number of events to be sent for testing.
you can change this count..
More reference,
http://www.tutorialspoint.com/android/android_testing.htm
http://androidtesting.blogspot.in/2012/04/android-testing-with-monkey-tool.html
I am trying to run the example code from the BigFlake Android samples, in specific this one example: CameraToMpegTest. I am new to Android development and I am not sure how I should treat this test suite. I try to create an Android Test Project in Eclipse but it doesn't run. Examples on the Internet seems to create an Android Test Project from a specific application project. Anybody tried to run these code and can give me some hint?
The bigflake samples were written as CTS tests, to be executed in the test harness (though some of them never actually turned into tests). If you're not set up with a full source tree it can be difficult to get them to work unmodified.
For a complete app example, see Grafika. The examples are a bit more involved, but you can get the code running more easily. In particular, "Continuous capture" and "Show + capture camera" will be of interest.
Background
As it turns out, it's quite an annoyance to test out in-app-billing (i've written about it here) . Each time you find a bug and need to test your app, you must have the following steps:
compile the app , preferably with the debuggable="true" flag on the manifest
sign the app with your real key you've created for the play store.
install the app on your device
run the app on your device, preferably debugging it via eclipse.
If you'd use a batch operation instead of doing all of those by yourself, it should make things easier to test such apps, and might also be useful for other apps as well.
The question
Is there any way to make the whole process fully automatic, so that with a single click of a button, it will do all of the above?
I know how to achieve 3+4 (using "adb.exe install -r *.apk" and "adb.exe shell am start -n FULL_ACTIVITY_PATH" ), but I don't know how to achieve the others.
If there is a solution that doesn't involve a third party app or plugin (like maven or Ant), it could be very nice. Of course, if that's what is available, I would like to know if it's possible to achieve via a batch file that will use them somehow.
Is there maybe a way to mimic how Eclipse does things in this regard, without being so specific on the project (maybe just the path of the project and that's it)?
Maybe you can package app by ant . You can do every thing you what int the ant code of packaging ,causing the core code is to make property configs in your app and referenced lib, such as build.xml,local.properties...,and replace channel in AndroidMainfest.xml ,so you can also replace any code in your android app,just as you want ,to change the flag of debug , because all the operation just handle local file before packaging your app,you can copy or modify any file in your app. After above process ,you get a app,then you can run other code to install the app. Recently ,I have been using the batch package method to get a lot of app for different channel .so hope it helps.
I'm using AndroidTestCase for unit testing. I have a unit test which is failing, but I haven't figured out how to display output from it. For example, I don't see the values I print using Log.d or System.out.println in the console nor the logcat output.
How do I view the unit test console?
With Android Studio 2.3.1, works using the old fashioned Java styled
System.out.println("Start Test");
Here you can see the output:
You shoud see the Log.d() messages in logcat unless your test is crashing much before (i.e in the constructor).
In my case ,
System.out.println("Test") is working for JUnits tests,
Log.d("tag" , "Test") is working for AndroidJUnit tests(Instrumented)
Go to Debug --> Logcat. Make sure the LogLevel and Filter are correct as well.
See the screenshot from Android Studio 1.1.0
Just to be clear, if you're running an emulator you have to use adb logcat.
Also, make sure you're using the standard android.util.Log.d() to send your output.
You probably disconnected the device/emulator and reconnected. You have to click on the device name again in the list in the Dalvik Debug Monitor for it to reload the logs and keep updating the output.