[android-developers] Re: View contact based on contact id - not always shows the right contact

2012-06-07 Thread A. Elk
A new dev guide for the contacts provider is now available on 
developer.android.com

http://developer.android.com/guide/topics/providers/contacts-provider.html.

On Wednesday, June 6, 2012 2:34:42 AM UTC-7, Balint wrote:

 I query the phone's calllog into a ListView. So when the user long clicks 
 an item, a dialog comes up with options, including View contact. To be 
 able to view the contact the intent needs the contact id. From the calllog 
 I get the contact id by the phone number.
 My problem is that I not always get to see the right contact. I click on 
 Peter, and Peter's contact sheet comes up. I click on Sarah, and Jason's 
 contact sheet comes up.

 I must have been using this code the wrong way. Please help.

 ContentResolver contentResolver = getContentResolver();
 
 Uri uri = 
 Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, 
 Uri.encode(phone));
 
 Cursor cursor =  contentResolver.query(uri, new String[] 
 {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID}, null, null, null);
 
 if(cursor!=null) {
while(cursor.moveToNext())
{
   String contactName = 
 cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
   contactid2 = 
 cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup._ID));
   }
   cursor.close();
 }
   
 Intent intent_contacts = new Intent(Intent.ACTION_VIEW, 
 Uri.parse(content://contacts/people/ + contactid2));
  startActivity(intent_contacts);

 Maybe what I need is not the PhoneLookup._ID, but some other ID.

  - on a HTC Desire HD (2.3.5) I get the proper contacts in 99% of the
cases.
  - on a ZTE Blade (2.2) I get the proper contacts in 60% of the cases.
  - on a Samsung Galaxy Ace (2.3.3) I get the proper contacts in 5% of the 
 cases.

 What the hell is going on???


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Associate app with Email attachement

2012-05-14 Thread A. Elk
You can't force an app you don't own to use only your app to handle an 
Intent. That's not the Android design philosophy.

The best you can do is put in an intent filter in your manifest for an 
intent. When that intent is matched, your app will get it, unless other 
apps also match. If more than one app matches, the user gets a chance to 
pick the one to use. Users can choose to use the app they've picked for all 
similar actions, after which the chooser is no longer activated and the 
intent goes directly to the chosen app.

What you can do is tell users to choose your app when they open a CSV file. 
If that option doesn't appear, they have to clear options in the mail app's 
entry in App settings.

This is a feature. If you forced users to use your app for *any* CSV file, 
they'd never be able to look at Excel CSVs, etc.

What you might want to do is use your own custom MIME type for the file 
you're sending. You can still use CSV format, but with a custom MIME type 
you can have an intent filter that only handles that type.

On Sunday, May 13, 2012 11:07:29 PM UTC-7, Kanika Sayal wrote:

 I am developing a simple application where the requirement says that 
 If there is any email attachment with .csv file extension then on long 
 press of that email attachement should open an option to user that 
 Download and open this attachment with MYAPP. So When the user 
 clicks on MyAPP then it automatically get downloaded and open with 
 MYAPP.. Here I am using IntentFilter, but that IntentFilter works 
 after that attachment downloaded and saved into sdcard. 

 So anyone please help me on how can I implement that Click on email 
 attachment would open an option to open the attachment with myapp?? 

 Thanks...

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] newbie SQL Light Question

2012-04-25 Thread A. Elk
It's an abstraction, to be sure, but it also protects you from malicious 
SQL injection. Forming raw SQL statements, especially from user input, 
allows users to hack the sense of your statement in truly evil ways.

Using query() avoids this. All of the parameters of the query are passed in 
as arguments. No strings are concatenated, and no statement compilation is 
done. There's no way for the user to inject malicious SQL.

Notice the ContentResolver.query() method. It has both a selection and 
selectionArgs parameter. To be safe, use the selection argument for 
column names and operators, and put the values to compare to in 
selectionArgs. The values are inserted into the selection clause 
without concatenation, so no SQL injection can occur.

On Wednesday, April 25, 2012 2:44:39 PM UTC-7, MagouyaWare wrote:

 This is an abstraction so you don't have to build the SQL query yourself.  
 If you want more flexibility you can use the rawQuery() method:

 http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery%28java.lang.String,%20java.lang.String[]%29

 Thanks,
 Justin Anderson
 MagouyaWare Developer
 http://sites.google.com/site/magouyaware


 On Wed, Apr 25, 2012 at 3:38 PM, g...@deanblakely.com 
 g...@deanblakely.com wrote:

 I'm learning SQLLite using the NotePad tutorial appication.  The code
 pasted below is very strange to me.  I'm used to using SQL i.e. Select
 KEY_ROWID, KEY_TITLE, KEY_BODY from DATABASE_TABLE
 WHERE BLAH BLAH BLAH.

 One of the nice things about SQL is that it is pretty much the same
 between the platforms so when a developer has to learn a new platform,
 such as Android, the SQL is the same.

 What's going on?  Why don't you use SQL?
 Thanks,
 Gary

   public Cursor fetchNote(long rowId) throws SQLException {

Cursor mCursor =

mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
KEY_TITLE, KEY_BODY}, KEY_ROWID + = + rowId,
 null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;

}

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Contact UI Question

2012-04-25 Thread A. Elk
You don't have to create your own contact editing UI. You can send an 
intent to the contacts app, which will bring the app to the foreground, 
displaying the Add Contacts screen. You can send extras that will populate 
the screen with data. See the javadoc for ContactsContract.Intents.Insert. 
If you send the intent with startActivityForResult(), you'll get a callback 
to onActivityResult(), which has an intent argument. The data field for the 
intent contains a content URI for the newly-added contact.

On Wednesday, April 25, 2012 7:48:13 AM UTC-7, Mark Phillips wrote:

 In my application, I need to collect information about (most likely) new 
 people for the phone's contact database (eg players on a sports team). I 
 see how to add the information using the Contacts API (
 http://developer.android.com/resources/articles/contacts.html). I was 
 thinking of adding the contact with a new group name, so I can easily find 
 them again and display just those the names in a ListActivity.

 What about the ui for creating and editing contacts? Do I have to create 
 my own contact editing ui, or is there a way to drop the user in the 
 native edit contact ui to enter the information about the contact, and 
 then bring them back to my app's ui when they are done?

 Thanks,

 Mark


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Contact UI Question

2012-04-25 Thread A. Elk


On Wednesday, April 25, 2012 7:48:13 AM UTC-7, Mark Phillips wrote:

 In my application, I need to collect information about (most likely) new 
 people for the phone's contact database (eg players on a sports team). I 
 see how to add the information using the Contacts API (
 http://developer.android.com/resources/articles/contacts.html). I was 
 thinking of adding the contact with a new group name, so I can easily find 
 them again and display just those the names in a ListActivity.

 What about the ui for creating and editing contacts? Do I have to create 
 my own contact editing ui, or is there a way to drop the user in the 
 native edit contact ui to enter the information about the contact, and 
 then bring them back to my app's ui when they are done?

 Thanks,

 Mark


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Launching default messaging app for mms

2012-03-25 Thread A. Elk
The chooser is a system function, and not one that you can create. It 
appears automatically if  application A sends out an intent and gets a 
match from more than one destination application [B,C,D...] . In the 
chooser, the user can select a default application X to use for the intent 
that application A sent out. After that, X is launched every time that *
intent* is sent out, regardless of the application that sent it.

For example, if  my application sends an intent with the action ACTION_VIEW 
and the MIME type image/jpeg, most users will get a chooser, because 
applications that can view JPEG images are quite common. If the user 
chooses some graphics application X as the default, then any time *any* 
application 
sends an intent with ACTION_VIEW and MIME type image/jpeg, application X 
will launch:

*IMPORTANT EXCEPTION:* An application can provide additional levels of 
filtering that narrow down the applications that will respond to an intent. 
To learn more, read the *Intents and Intent Filtering* guide in the 
Developers Guide.

If you want a specific application to handle your intent, you have to be as 
specific as possible with the intent data. The most narrow specification 
you can make is the component name and class of the target activity or 
service. On the whole, though, you should avoid being too specific. The 
intent framework allows the user to pick and choose applications for 
various tasks; be too specific, and you're taking functionality away from 
the user.

If you send an intent, be sure to specify an action and a MIME type, if 
nothing else. If you handle incoming intents, be sure to set up your intent 
filters correctly and test them.

On Sunday, March 25, 2012 2:27:46 AM UTC-7, Farhan wrote:

 Hi all, 
 I am working on an application that allows user to create mms messages 
 according to a template, for android 2.2. I am done with most of the work, 
 but I am stuck with one thing. I want to be able to launch the android's 
 default messaging application to send the mms. I tried to set package of 
 the intent as com.android.mms and it seems to work fine on my phone, as 
 well as emulator, but it is showing a chooser for the mms intent to my 
 friend. I am not creating a chooser anywhere, still. Can anyone help me get 
 through this. A little guidance is I think all I need. Thank you

 Regards

 Farhan


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Launching default messaging app for mms

2012-03-25 Thread A. Elk
There is no default messaging app. Any messaging application that chooses 
to handle MMS can respond to this intent. If the *user* chooses to make one 
of the applications a default, then it becomes one until the user unsets it 
as the default.

You seem to have a reason for wanting one application to handle MMS. I 
would like to know why. Perhaps I can provide further wisdom in this 
regard. In general, Android promotes the idea of letting the *user* decide 
which application to use.

On Sunday, March 25, 2012 4:21:57 PM UTC-7, Farhan wrote:

 Intent picMessageIntent = new Intent(android.content.Intent.​ACTION_SEND);
 picMessageIntent.putExtra(​address, Some Numbers);
 picMessageIntent.setType(​image/jpeg);
 picMessageIntent.putExtra(​sms_body, Some Text);
 picMessageIntent.putExtra(​Intent.EXTRA_STREAM, Uri.fromFile(file));
 picMessageIntent.setPackage(​com.android.mms);

 Yes, I understand now that the package may not be there in a device, so it 
 is giving a chooser. 

 Is there a way to find the default messaging application or the built-in 
 messaging, and set its package in the intent above?


 On Sun, Mar 25, 2012 at 5:29 PM, Justin Anderson magouyaw...@gmail.comwrote:

 I tried to set package of the intent as com.android.mms and it seems to 
 work fine on my phone, as well as emulator

 You don't want to do this... Not all phones will have the stock android 
 app with that package name.  Many manufacturers replace stock android apps 
 with their own for things like the camera, sms, etc...

 Also, there are a lot of 3rd party apps out there that handle sms/mms... 
 If a user has installed a 3rd party app then they probably don't want to be 
 tied down to the one that came on the device.


 but it is showing a chooser for the mms intent to my friend. I am not 
 creating a chooser anywhere

 If that is the case then what is most likely happening is that your 
 friend has more than one sms/mms app on the device.  You probably also will 
 notice that the chooser has a checkbox that, if checked, will make their 
 selection the default from then on.  If they check that box and choose 
 which app they want to use to send the sms/mms message then the next time 
 you run your app you will not get a chooser.

 This is how standard Android works.  Please don't force people out of the 
 standard.


 Intent it = new Intent(Intent.ACTION_VIEW); 
 it.setType(vnd.android-dir/​mms-sms);

 I have never created an app dealing with sms/mms messages before, but I 
 don't think this is the way to go...  ACTION_VIEW generally means that you 
 are wanting to display something, not create and/or edit something.  Unless 
 I am misunderstanding what you are trying to accomplish, you should 
 probably use ACTION_SEND.  What does your intent actually look like?


  

 Thanks,
 Justin Anderson
 MagouyaWare Developer
 http://sites.google.com/site/​magouyawarehttp://sites.google.com/site/magouyaware



 On Sun, Mar 25, 2012 at 5:02 AM, Daniel Hoeggi hoeggerl.dan...@gmail.com
  wrote:

 try this

 Intent it = new Intent(Intent.ACTION_VIEW); 
 it.setType(vnd.android-dir/​mms-sms); 

 On Sun, Mar 25, 2012 at 11:27 AM, Farhan Tariq farhan@gmail.comwrote:

 Hi all, 
 I am working on an application that allows user to create mms messages 
 according to a template, for android 2.2. I am done with most of the work, 
 but I am stuck with one thing. I want to be able to launch the android's 
 default messaging application to send the mms. I tried to set package of 
 the intent as com.android.mms and it seems to work fine on my phone, as 
 well as emulator, but it is showing a chooser for the mms intent to my 
 friend. I am not creating a chooser anywhere, still. Can anyone help me 
 get 
 through this. A little guidance is I think all I need. Thank you

 Regards

 Farhan
 -- 
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to 
 android-developers@​googlegroups.comandroid-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+​unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/​group/android-developers?hl=enhttp://groups.google.com/group/android-developers?hl=en


  -- 
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to 
 android-developers@​googlegroups.comandroid-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+​unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/​group/android-developers?hl=enhttp://groups.google.com/group/android-developers?hl=en


  -- 
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to 
 

[android-developers] Re: Notifications when App in background!

2012-03-25 Thread A. Elk
There's an alternative way of handling this that doesn't require opening an 
Activity.

The new Android Design guide is a good reference for this.

Although the existing Developer Guide conflates the two, dialog boxes and 
notifications are fundamentally different UI experiences. It's important to 
choose the right one, based on the UI situation at the moment.

A dialog is an *alert*, which brings attention to a situation in the 
currently-running activity. A Toast can also be an alert. In general, you 
should reserve Toasts for informative messages that confirm a user action. 
A dialog box is better suited to unusual conditions that the user should 
consider before moving on to another operation. You should use both of them 
with a bit of reserve. When possible, anticipate what the user would do 
next, and do it. For example, don't ask users if they want to make another 
move in a game if you already know that they can't. This is just annoying.

A *notification* is a report from some part of an application that is not 
in the foreground, which sounds like the situation the OP is encountering. 
Notifications are displayed in the status bar. You can set the notification 
so that the user can remove it from the status bar by clicking it or 
sliding it. You can also set the notification so that it can only be 
removed by an application. One of these is what the OP is looking for.

You should handle C2DM broadcasts in the background, in a service. The 
service can send a notification to the status bar. It could also send an 
intent to an Activity, but I don't think that's necessary. Anything related 
to communications between the network and your app should be done in the 
background. Of course, one should *never* pop an Activity into the 
foreground. Make the notification, then let the user decide what to do. If 
you think about it, all of the default applications that come with Android 
do this.

BTW, handling notifications this way has nothing to do with C2DM. Anything 
that's not of immediate interest to the user should happen in the 
background, and any information that comes from the background should go 
into a notification.

On Friday, March 23, 2012 4:31:33 PM UTC-7, PinkFluffyBunny wrote:

 Hi friends, 

 I have implemented push notification for my Application using c2dm,but 
 when I send a notification to the application, I need to open the app 
 to see the notification alert dialog box. 
 If an push notification is sent when the application is closed or 
 minimized (running in background) then the notification alert will not 
 pop up till we open the application window. 

 I want the notification to pop up even when the app is running in the 
 background or is stopped. It can pop the alert as a banner at the top 
 that stays for sometime and goes away or it can be a alert dialog box 
 that needs to be dismissed. 

 Are there any parameters specific in the payload or header that need 
 to be specified to achieve this? 

 How to acheive this ??? Please help! 

 Thanks! 

 -- 
 Thanks , 
 Vani

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Extended Application life time.

2012-02-15 Thread A. Elk
A continuously-running Service is not always bad. Sometimes this type of 
Service is necessary.

For example, sync adapters use a service that's always running, and they 
may also use an Application object to instantiate and return a singleton. 
This allows the SyncManager to start synchronizations without user 
intervention. This pattern is visible in the SampleSyncAdapter sample app.

If you use an Application object or a continuously-running Service, give it 
a descriptive name, such as SyncAdapterService or SyncAdapterModule.

It's true that users attack apps with task killers and force stop, even 
though Google tries to get the message out that they shouldn't do it. 
However, this shouldn't make developers fearful of background services. If 
you need an always-on Service, use one, but also look at alternatives 
that don't require one.

Apparently, you want to sync location to a server on a regular basis. If 
you're sending the location to the server every so many minutes/seconds, 
you can probably use AlarmManager and IntentService. Even so, you have to 
handle error conditions, such as the server not being available.

If you're truly synchronizing data between a server and the device, and 
you'd rather let the system handling all the ugly details, use a sync 
adapter. The system will schedule sychronization automatically, check 
network availability, restart interrupted syncs, and handle authentication 
if necessary.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: testing onActivityResult

2012-02-10 Thread A. Elk
I think that the reply meant that you need to write a test harness that 
monitors your activity and the destination activity.

However, what you're trying to do is not a unit test, and 
ActivityInstrumentationTestCase2 is a unit/functional test case class, not 
a generic testing class. It will test the internal workings of the activity 
under test. It has no knowledge of anything beyond that, so in general you 
can't launch an outside Activity or get results back from one.

To run part of a test on the UI thread, call getActivity() to get a handle 
to the activity under test, then call Activity.runOnUiThread() to execute 
methods in the activity.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Database management

2012-02-09 Thread A. Elk
You can't access files that don't belong to your application unless the 
file's creator makes them world-readable. This is a security feature. The 
same is true for databases.

I think there are content providers for MMS and SMS. Look in the Android 
Open Source repository. They're not documented, though, which means they're 
subject to change without notice. You'd have to figure out how to use them 
from the code, and then hope that you can get the proper permissions to 
access them.

You must never try to work directly with files unless the owner makes them 
world-readable *and* gives you permission to do so. To do otherwise is a 
security violation, and I suspect it's also a violation of your terms of 
service with Google. Worst of all, you would be showing that you are a Bad 
Person. In Android, stuff is made inaccessible for a reason. No matter how 
much you'd like to look at it, you're better off doing something else.

I'd like to know *why* you need to do this. It's always better to ask How 
do I manage SMS messages, even if they're not mine rather than asking How 
to I get around a fundamental feature of the platform that isn't meant to 
be gotten around?

Of course, you may be doing this for your own device, with no intention of 
distributing the app. Even so, if you're using APIs that are not in the 
public reference, you have no guarantee of long-term stability.


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Problem Creating new Contact with photo

2012-02-09 Thread A. Elk

   
   1. As far as I can tell, you're trying to create a new raw contact with 
   an account name and account type set to null. This is a bad idea, even 
   though it will work. The Contacts Provider depends on raw contacts having a 
   particular account type and account name; these indicate the source of 
   information that's synced with cloud-based services. It's assumed that your 
   app has some non-null value for these. For account type, come up with a 
   namespace that's unique for your application; for account name, use a 
   string that identifies the device's user.
   2. I'm not sure what you mean by Contact List, but if you're looking for 
   your results in the People app, then the problem may be that you're 
   assuming the entries are raw contacts. They're not. When you add a raw 
   contact, the Contacts Provider automatically generates a new Contact behind 
   the scenes. The People app lists contacts, not raw contacts. Your timing 
   may be off. If you're concerned that your raw contact isn't being created, 
   write tests in the code to verify that your insert worked.
   3. I can help you more if I can find out more about what you're trying 
   to do with your app. The People app can already add raw contacts with 
   photos. What is it you're trying to do that's different?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Newbie question about Content Provider

2012-01-20 Thread A. Elk
Are you talking about a content provider or an SQLite database? They aren't 
equivalent. A content provider *may* use an SQLite database as its database 
repository, but it doesn't have to, and you can't assume that it does.

*If it's a content provider:*

You can do an insert followed by a query. Generally, it has to be done in 
two separate method calls:

ContentResolver.insert();
ContentResolver.query();

One row can be inserted per insert().

You can also do a transaction using ContentProviderOperation objects and 
then ContentResolver.applyBatch();

*If it's an SQLite database:*

You can do anything you can do in SQLite itself, using the classes in 
android.database.SQLite. Remember, though, that in general you *can't* use 
SQLite classes against a content provider (in general).

*In addition:*
*
*
If this doesn't answer your question, you might try to explain your use 
case rather than simply asking if SQLite operations translate to Android.


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Share file or an variable between 2 apps

2012-01-19 Thread A. Elk
Are you sure that this is the assignment?

You can force two applications to have the same UID by using an attribute 
of the manifest element in AndroidManifest.xml. This is documented in 
Security and Permissions, 
http://developer.android.com/guide/topics/security/security.html. This 
guide also describes the ramifications of sharing a UID. Once you do this, 
the two application are treated as one by Android, so they share the same 
sandbox. This means that a file written by one can be read by another. To 
share a variable, you could create an object and then serialize it to a 
file.

However, I strongly recommend against doing this sort of thing. It's not 
the way Android is designed to work. Applications should avoid knowing too 
much about one another. An application A should use common APIs to send 
information to an application B, with the assumption that B could be 
anything.

In summary, I think it's a bad assignment.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: content provider

2012-01-19 Thread A. Elk
A sync adapter doesn't automatically communicate data to and from the 
cloud. It's more of a convenience class that scopes out the methods you'll 
need to implement in order to *synchronize* data linked to a particular 
user account, and do it on a regular schedule. In that way, a sync adapter 
ties into the synchronization infrastructure that's part of the OS.

The documentation uses content providers because the primary use case for a 
sync adapter is communicating data from a cloud service to and from a 
central repository of data on the device. The easiest way to manage such a 
repository is a content provider, but it's not mandatory.

From what you've said, you want to move the files from the device to the 
cloud. Do you want to move files from the cloud to the device, such that 
you can force the cloud and the device to have the same versions? 
Synchronization is not just moving files back and forth; it's *intelligent* 
movement 
that guarantees that two places have the same data. If you need that, then 
you need synchronization. Of course, even if you're *not* synchronizing, 
you need some sort of network transport, but if you're just sending files 
to the cloud then you don't need a sync adapter.

The Android sync adapter framework assumes that sending data to the cloud 
requires authentication and authorization, which is reasonable for 
real-world use cases. The sync adapter is associated with a user account, 
so the user doesn't have to enter credentials every time a sync occurs. The 
rest of the work is having the sync adapter figure out what needs to be 
updated on the device, and then what needs to be updated on the cloud. Even 
if you're using files, it's easier to track the device state within a 
content provider. You can write a content provider that tracks metadata in 
tables but also has URI links to files you have stored on the device.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Retrieving Information from the ContactsContract API

2012-01-12 Thread A. Elk
To retrieve something from the Contacts Provider, you need to use the 
content provider client class android.content.ContentResolver and its 
query() method.

A query requires the *content URI* of the part of the provider you're 
trying to query, a *projection* (the list of columns you want to retrieve), 
*selection clause* (think SQL WHERE clause without the WHERE keyword), 
*selection 
arguments*, and a column name to use as the *sort order*. The method 
returns an android.database.Cursor object.
Selection clause and selection arguments allow you to parameterize the 
clause. For example, you can set the clause to some_column_name = ? and 
the arguments array to {Harry Truman} and the resulting clause should be 
interpreted by the provider as some_column_name = 'Harry Truman'.

Think of a Cursor as a list of rows returned from the provider. You 
traverse the rows with Cursor.moveToNext(), and get individual columns from 
a row with index = Cursor.getColumnIndex(column_name) followed by var = 
Cursor.getText(index). There are actually several different get methods 
for different data types.

Now to the Contacts Provider. It gets tricky, because the definition of 
contact is more complex (but more flexible) than you may think.

The provider really tracks what are called raw contacts. A raw contact is 
the representation of a person, defined by a name, a user account, and a 
user account type. For example, Harry Truman for the device owner's 
Google Contacts account *someu...@gmail.com* is a raw contact. Harry 
Truman for the device owner's Twitter account *myTwitterID* is a *separate* 
raw 
contact. All of the raw contacts that seem to be the same person are linked 
to a single Harry Truman contact. There are two separate tables in 
Contacts Provider: RawContacts and Contacts.

Detailed information for a person, such as emails, postal addresses, and 
phone numbers, is stored on a raw contact basis; contacts don't have any 
independent details other than minor stuff. There can be several detail 
rows for each raw contact; in fact, a raw contact can have several email 
address rows. The documentation isn't easy to understand, because the Data 
table that stores detail information is the *one* table for *every type* of 
data row. Email addresses, phone numbers, and postal addresses are all 
stored in the same table, even though they obviously need different column 
names. The provider implements this by defining generic column names DATA1 
through DATA15, and then defining aliases that are type-specific.

To see this, look at the Javadoc for 
ContactsContract.CommonDataKinds.Email. At the top, you'll see a table with 
the data columns and aliases.

When you access columns, you use the aliases.

The provider, however, makes it much more simple to look at the data. Use 
the constants in ContactsContract.Contacts to retrieve the contact you're 
looking for (or all of them, if you want). Get the _ID value for each 
contact row. Use this to retrieve the raw contact. Given that, use the 
column names defined in ContactsContract.RawContacts.Entity to retrieve the
detail data for a raw contact. The entity is a join of a raw contact and 
all of its detail rows.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Retrieving Information from the ContactsContract API

2012-01-12 Thread A. Elk
I think that the interface (and its documentation) is complex because the 
provider is designed to handle a large number of current and future 
situations.

There's more than one email row for a raw contact because a contact can 
obviously have multiple email addresses. All of the emails, addresses, and 
phone#s are stored in one table because of expandability: adding a new type 
of detail record doesn't require another table. Different types of rows 
(email versus postal address, etc.) are distinguished by their MIME_TYPE 
column, so adding a new type of data simply means adding a new MIME_TYPE. 
Notice that anyone can add their own type of data, though there's no 
guarantee that anybody else will be able to use it.

There's multiple raw contacts attached to a single contact to provide much 
more flexibility than other contacts systems you may be familiar with. Each 
source of contacts information (Google Contacts, Microsoft Exchange, Yahoo 
Mail, Twitter, Facebook, etc.) can put its own version of a contact into 
the Contacts Provider. They don't overwrite each other, and yet the 
contacts row aggregates them so that you can find them easily. It's not 
obvious, but the Contacts Provider assumes that most contact information is 
synchronized with an external system. You may get your contacts from Google 
Contacts, or you may enter them on your device and send them somewhere, but 
it's rare that you don't use something on the cloud as well as Android for 
contacts. Having multiple raw contacts means you don't have to choose which 
system you sync with; you can sync with *all* of them. Aggregating multiple 
raw contacts under one contact means that you can see all of the 
information just by searching on a name.

To summarize what you see for the Contacts Provider in the Javadoc:

   - The interfaces whose names end in Columns are constant definitions 
   for table columns. They're defined as interfaces so a table class can 
   inherit more than one of them at once.
   - The CommonDataKinds classes define constants for commonly-used values. 
   They're not columns, but what columns *contain*.
   - The Contacts class and subclasses define stuff for the contacts table.
   - The RawContacts class and subclasses define stuff for the raw contacts 
   table.
   - The Data class and subclasses define stuff for the data table.
   - Everything else is auxiliary tables that you usually don't have to use.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Retrieving Information from the ContactsContract API

2012-01-12 Thread A. Elk
Oops! I forgot to say that there's also a ContactsContract.Contacts.Entity 
class. You can use this to join contact to raw contacts to details.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers]Why insert row into table return null?

2011-06-02 Thread A. Elk
Some comments:

   1. You use getContentResolver().insert(uri,values) to insert a row into a 
   content provider. Please don't equate content provider = database. Though 
   many content providers are implemented as databases, it's not a requirement. 
   *In particular*, a database provides operations such as join that a 
   content provider is not required to implement.
   2. A null result from a content provider method *usually* indicates an 
   error. 
   In particular, the common pattern for query is to return null if an 
   internal error occurred (for example, an invalid URI). If no records match 
   the query, the common pattern is to return a Cursor with no records.
   3. Since you're getting null for insert, the first thing I'd check is 
   the URI value you're passing in.

A. Elk

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Android testing with android library

2011-05-23 Thread A. Elk
The Android test case classes provide a way to *unit-test* a method or 
methods that have to run in the Android environment. Since they do unit 
tests, you should be able to test your library code within a larger .apk 
test harness. One way to do this would be to build a purpose-coded test 
harness. Other way would be to compile the library code together with one of 
the apps that uses the library code. In either case, you should then have a 
.apk that you can test.

If you have some sort of condition that only appears when an app uses the 
library project, then you have something that's beyond unit testing. The 
test case classes may or may not help you, since they're not designed for 
functional testing.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: How to use the new clipboard function?

2011-03-31 Thread A. Elk
Your statement is imprecise.

android.*text*.ClipboardManager is being deprecated, in favor of android.*
content*.ClipboardManager. The javadoc for android.text.ClipboardManager 
points to the new API.

Nothing in the documentation suggests that the old way of copying and 
pasting text is any different from the new way. Only the package name is 
different. That sometimes happens.


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] best way to storage data on android

2011-03-22 Thread A. Elk
Content providers don't provide a database, or anything else for that 
matter. They are an Android component that offers the following features:

   - cross-application access, so that one data store can serve multiple 
   applications. The framework handles data transfers and procedure calls 
   across processes.
   - Flexible resource identification based on URIs.
   - Implementation hiding - a provider can manage its data however it 
   wants, but it must offer its data as one or more data sets.
   - Each data set is *accessed* like a single SQL table of rows and 
   columns, regardless of the underlying structure of the data.

Basically, you don't get automatically get a database when you create a 
ContentProvider, and in fact you have to implement the underlying data 
structure yourself.
Providers are there so that applications can offer an unattended source of 
data to other apps. The provider is always available, and Android starts it 
up automatically when
an app tries to access it. A newer reason for providers is copy and paste: 
if you want to copy and paste complex data structures, binary data, or file 
streams, you have to
use a content provider.

There are also some convenience methods in the content provider framework 
for managing synchronization. This is useful if you want to allow updates 
both from Android
apps and from the Internet.

For a list of restaurants with street addresses, latitude and longitude, and 
pictures, a database is *probably* the best idea. Over time, it will be the 
easiest to manage. The
alternatives are storing it in a text file (containing pointers to the image 
files), but that only works for a small set of data that you don't update a 
lot.

If you want this data available to all applications on the phone, you really 
have to use a content provider. Otherwise, your own SQLite database will be 
easier to handle, even
if you're doing internet updates.

I think SQL and SQLite are easier than people think. They get complicated if 
you try to decompose them to canonical form, but you can always get your 
code working first and
then do that later, since the decomposition and joining are done with SQL, 
not with Java.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Questions about Activity.finish() and a couple of other things.

2011-03-18 Thread A. Elk
Certainly testPreConditions() should be executed. Which version of the SDK 
are you using?

As for the Activity not being finished, I'm not sure what Android does in 
response to mActivity.finish(). I can't really understand what you mean in 
the second paragraph after the code snippet. Seems like you use debug to 
change the values from the ones that were set by the test, and you verify 
that you can see these values in testStateDestroy().

Remember that you're testing the Activity outside of its normal operation. I 
wonder if you *would* see the spinner on the screen, even if the Activity is 
running.

I wouldn't assume that System.gc() does anything useful. The description of 
the method is Indicates to the virtual machine that it would be a good time 
to run the garbage collector. Not clear to me that the garbage collector is 
what Android uses at the thread/process level, nor is it clear to me that 
Android is inclined to GC apps unless there's severe memory pressure. From 
all I can see, Android wants to keep stuff around if it can. Android 
developers have to learn to let go, and trust that they can leave their 
app running.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: ProgressDialog not showing

2011-03-15 Thread A. Elk
What I do is reverse the order of the operands:

if (true == result)

or

if (0 == result)

and so forth. If you get the operator wrong, you'll get a compile
error.

Kostya's style works too.



On Mar 15, 11:36 am, Kostya Vasilyev kmans...@gmail.com wrote:
 15.03.2011 21:29, David Williams ?:

  Thanks.  I'll go smack myself around the face a little now.

 Better yet - get in the habit of writing

      if (booleanValue)

 or

      if (!booleanValue)

 Without == or = :)

 I'm actually surprised there is no compiler warning for this.

 -- Kostya

 --
 Kostya Vasilyev --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Query in Android Application development

2011-03-14 Thread A. Elk
There's no reason to use a content provider to work with databases. A
content provider provides a common, abstract mechanism for offering
data to other applications. Its power is in handling all the small
details of connecting an application to a data source in another
process. The content provider framework has a few useful methods for
dealing with databases, but that is *not* its main focus. Don't get
hung up on content providers to provide data, especially if the only
use of the data is in your own application.

If you run into an error you can't figure out, or you need help with a
specific design decision, then this forum will work for you. If you
just say Here's what I want to do, how do I do it? we *can't* help
you effectively. We are bound to leave out some important detail that
you know. We can't substitute for experience and training.

To answer the OP:

You say that you need to create an SQLite DB to check if the user is
valid. That is fairly easy to do in Android, and it's documented in
the Dev Guide. However, you go on to say that the purpose of this DB
is to verify that the user is registered. You also note that the check
needs to be done on a website, not local to the device. If the user is
new, then he or she has to register on the website.

I can't see why you need a local database. All the information is on
your website. It seems to me that you want the user to go to the
website to login, and then proceed locally. This is tricky to do, but
not impossible. However, I don't see that you have to keep *any*
database data on your device, unless you're using it as a cache of
users.

As far as the ways that you've used hardly never worked fine, you
will have to post a specific method you used, and what happened.

On Mar 11, 9:34 pm, Chambras marcech...@gmail.com wrote:
 I think that the best way to work with DBs is using content providers you
 can read the documentation about them 
 here:http://developer.android.com/guide/topics/providers/content-providers...

 also I would read the samples in the resources sections they have everything
 you need in order to start developing in android, sample code, tutorials,
 articles, everything

 http://developer.android.com/resources/index.html

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: ANN: Mock Objects on Android with Borachio

2011-03-14 Thread A. Elk
Good work. I have a couple of comments:

If you have POJOs in your code, you can test them with JUnit using a
standard mocking framework of your choice. The only limitations on
mocking are imposed by the Android system.

Without getting into too much detail, most of the objects in the
Android API can't be mocked. This is known. It's not meant to be test-
hostile, and it's not accidental. I always think that to get anything
useful in a finite amount of time, one has to make tradeoffs.

Some of the class names could have been chosen better, perhaps.
However, their functionality is well-documented.

I think the key thing is that you've produced something useful for
Android developers.

On Mar 13, 10:25 am, paulbutcher paulrabutc...@googlemail.com wrote:
 One of my biggest frustrations with writing code for Android has been
 the fact that none of the current Java mocking frameworks work on
 Android’s Dalvik VM. I recently released Borachio a native Scala
 mocking framework which does work on Android.

 Because Borachio is written in Scala, you’ll need to write your tests
 in Scala. But it can be used to test code written in Java.

 There's a description of how to use Borachio on Android on my blog:

 http://www.paulbutcher.com/2011/03/mock-objects-on-android-with-borac...http://www.paulbutcher.com/2011/03/mock-objects-on-android-with-borac...http://www.paulbutcher.com/2011/03/mock-objects-on-android-with-borac...

 I'd be very interested in any feedback!

 --
 paul.butcher-msgCount++

 Snetterton, Castle Combe, Cadwell Park...
 Who says I have a one track mind?

 http://www.paulbutcher.com/
 LinkedIn:http://www.linkedin.com/in/paulbutcher
 MSN: p...@paulbutcher.com
 AIM: paulrabutcher
 Skype: paulrabutcher

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: passing arrays between classes using intent

2011-03-14 Thread A. Elk
Is this a trick question? Some web app protocols do this! I admit that
they're way out of date, but that design pattern is still around
haunting us.

Storing state data for a web app is not always that easy.

Fortunately, Android can handle this better than some old web
frameworks. A database is a good solution, especially since they're
relatively easy to set up.

On Mar 13, 6:16 am, Mark Murphy mmur...@commonsware.com wrote:
 On Sun, Mar 13, 2011 at 8:49 AM, Chetan Singh Bisht

 chetanbish...@gmail.com wrote:
  hi, i am developing a final year project where i need to retrieve
  details of hospitals like name ,address, location(in terms of latitude
  and longitude) from a server and display them on a mapconnectivity
  has been established and i am able to retrieve the values in the from
  of array like address[], name[] etc..

  now i need to pass these values from an activity class to map activity
  class..

 What you really need is a central spot to hold that data, such as a database.

 Think of a Web app. Would you pass the entire contents of your
 details of hospitals in GET parameters from one Web page to another?
 Or would you hold the details of hospitals in a central place (Web
 server) and use the data from both pages?

 --
 Mark Murphy (a Commons 
 Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy

 Android 3.0 Programming Books:http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: drag and drop view in android?

2011-03-14 Thread A. Elk
This probably won't help most people, but Honeycomb includes a drag
and drop framework.

On Mar 14, 5:48 am, TreKing treking...@gmail.com wrote:
 On Mon, Mar 14, 2011 at 5:59 AM, Hitendrasinh Gohil 

 hitendra.virtuei...@gmail.com wrote:
  i  want reordering of the list row by drag and drop.
  means if i drag first row and drop at 5th position the view should
  be updated.

 http://tinyurl.com/6eqvtp9

 --- 
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
 transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How do I take back-up of all contacts and call log information.

2011-03-14 Thread A. Elk
You realize that all of your contacts can be synchronized to a Google
account in the cloud. That's a much better way of backing them up than
storing the backup on your device, IMHO. You can do a complete reset
and still get your contacts back in perfect shape.

Call logs are a bit different, but the Market has apps for backing
them up to storage. You can then use USB to copy them off.

On Mar 13, 12:10 am, abhijeet talktoabhij...@gmail.com wrote:
 Hello,

 I am trying to write an application that will take a backup of all my
 contacts and call logs so that I can restore them whenever required. I
 have studied the com.android.app.backup pacakage but I encountered
 that there is no agent for backing up the Database.

 Initially I thought of making a copy of entire db file but this seems
 to create lots of data traffic. Is there any way through which I can
 do a incremental backup of database, that is backing up only those
 changes in database that are not available in previous backups ?

 Please let me know if you know any efficient way to do a backup of
 database.

 Thanks in advance!!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Using Eclipse write monkeyrunner

2011-03-14 Thread A. Elk
Although I don't think that monkeyrunner was designed to be used from
Eclipse.

Whenever you run into a problem with monkeyrunner, try it from the
command line first.

On Mar 13, 9:11 pm, Diego Torres Milano dtmil...@gmail.com wrote:
 Some hints to use monkeyrunner from eclipse can be found 
 athttp://dtmilano.blogspot.com/2011/03/using-android-monkeyrunner-from-...

 On Mar 11, 6:06 am, c j techandroid@gmail.com wrote:







  I need using monkeyrunner do some easy auto test but have some
  problem.

  Eclipse SDK 3.6.2 (Pydev 1.6.5 + Jython 2.5.2 + Python 2.7.1 +
  monkeyrunner.jar + google-collect-1.0-rc1.jar)
  jdk1.6.0_24
  android-sdk-windows

  i try this example in second line have wrong

 http://developer.android.com/guide/developing/tools/MonkeyRunner.html

  # Imports the monkeyrunner modules used by this program
  from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

  # Connects to the current device, returning a MonkeyDevice object
  device = MonkeyRunner.waitForConnection()

  error msg

   device = MonkeyRunner.waitForConnection()
          at
  com.android.monkeyrunner.MonkeyRunner.waitForConnection(MonkeyRunner.java:
  74)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
  Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
  java.lang.NullPointerException: java.lang.NullPointerException

  Please tell know where setting wrong.
  thanks!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Freezing When Using ActivityInstrumentationTestCase2

2011-03-03 Thread A. Elk
No, this shouldn't happen. However, to debug this, try the following:
- make sure you define the startUp() method for each test case. In it,
do
myactivity = getActivity();
  to store a handle to the activity under test.
- make sure you define the tearDown() method for each test case. In
it, do
myactivity.finish();
  to shut down the activity.

This ensures that each test method runs with a new instance of the
activity under test.

It therefore ensures that each test case runs with a new instance of
the activity under test.

If you are depending on an activity surviving across tests, then
you're not really doing a unit test. Each test method should be self-
contained, except for dependencies that you inject. The place to set
up dependencies across all the tests in a test case is setUp(). The
place to set up dependencies for a particular test is in the test
method. Each test method should assume that a new instance of the
activity is running, with no other assumptions other than the test
fixture (the sum of dependencies set up in setUp() and in the test
method).

Test cases themselves are just a convenience for organizing tests. You
could, if you wanted, put all your tests into one test case.

On Mar 2, 6:18 pm, Mooncheol Yang saile...@gmail.com wrote:
 Hi All

 I made test codes using ActivityInstrumentationTestCase2

 when I execute test case one by one in Eclipse, it works well.

 but when I execute all test cases, it freezes after one test case is
 executed,

 i guess that in ActivityInstrumentationTestCase2, after each test Case
 is executed, Android Test Framework is designed to  to kill activity
 and launch again, but after one test case is ended, it seems that
 Android test framework can't kill activity.
 so test is hanging...

 anyone like me?
 any reply will be helpful

 Thanks..

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Freezing Occurs When Executing Test Codes

2011-03-03 Thread A. Elk
Is this the same problem you reported in another message?

Could you describe the evidence that suggests that something is
freezing? Does the test package stop producing output? Have you
tried this both in Eclipse and from the command line?

I'm not sure why you say that the android test framework is not
stable. There may be a bug in it, but the code for it has been around
for a relatively long time. I don't recall anyone else reporting a
similar problem.

Also, it would help if you posted what version of the SDK you're
using. A brief description of your Activity and your tests would also
help.

If this happened to me, the first think I'd do is write two incredibly
simple activity test cases, put them into one test package, and run
them against the Activity in question to see what happens. It could be
that your Activity is crashing somehow. For an example of a very
simple test case, see NotePadActivityTest.java in the NotePad sample
app.

On Mar 2, 6:05 pm, Mooncheol Yang saile...@gmail.com wrote:
 Hi All

 I wrote test codes(Instrumentation Test of Activities ) and executed..

 it works well..  but sometimes  it's freezing

 so, I checked testcodes, i finally made conclusions that android test
 framework is not stable.

 test is executing  setup() - myTestCode() - teardown()

 i found after teardown() is finished and freezing is occurred.

 Anyone like me same situation?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Is SL4A a better tool to test android Applications

2011-03-01 Thread A. Elk
Although you don't have to have a developer phone (debug access) for
every type of testing, you do need one to run some of the developer
tools like Hierarchyviewer.

Also, remember that you can't do unit testing on applications that
aren't yours, even if you happen to know their internal details. Your
application and test package have to be signed with the same key.

The OP still hasn't answered my question about why he's trying to test
applications that he doesn't seem to own. That question may be beyond
the scope of this forum.

On Feb 28, 3:11 pm, metal mikey coref...@gmail.com wrote:
 For functional testing you can also use HP QTP (QuickTest
 Professional) in conjunction with plugins for it that allow testing on
 real mobile hardware*, such as M-eux. There's also integrations
 between Device Anywhere and HP QTP as well as IBM Rational Quality
 Manager.

 For application security testing, if you have the source code (or
 perhaps even just the .apk) you can use HP Fortify 360.

 *phone must be rooted.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Is SL4A a better tool to test android Applications

2011-02-28 Thread A. Elk
This question, like the previous one, is too hypothetical. We can't
anticipate the types of testing you want to do.

Are you trying to do qualification testing of a particular device? Are
you trying to unit test or functional test an application? Are you
trying to test an existing application against a platform?

It wasn't clear to me to begin with why you were trying to test
existing Android applications, and what level of testing you were
trying to do.

Robotium is another option for writing test suites. It uses Java
rather than Javascript, and it's based on the model of app testing
used by Selenium.

It's not clear to me that you can use anything to test a customized
application. If the OEM is providing its own Contacts framework, then
it may be completely unrelated to the Android Contacts framework. In
that case, SL4A probably won't work because it assumes that the
standard Android framework is available.

On Feb 27, 11:06 pm, Shyam shyamstri...@gmail.com wrote:
 Thanks buddy.

 I have one more query.

 For example, Lets say the device is cusomized with its own OEM
 applications.
 For eg, Contacts application is customized. With SL4A, can we test
 that Contacts application ?

 Thanks,
 Shyam

 On Feb 25, 11:17 pm, Indicator Veritatis mej1...@yahoo.com wrote:







  Better? Maybe not. But since there are diverse tools for diverse kinds
  of testing, you should also be aware 
  ofhttp://developer.android.com/guide/developing/tools/monkey.htmland
  DeviceAnywhere.

  On Feb 24, 9:51 pm, Shyam shyamstri...@gmail.com wrote:

   Hello Android Developers,
   Currently i am using SL4A to test the existing Android Applications
   like media player,Contacts,Calling etc. Is it the correct way to Test
   the android apps. If no, please suggest me a better tool to test
   android apps.

   Thanks a ton in advance.
   Shyam

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Insrumentation testing in Android

2011-02-11 Thread A. Elk
As far as I can tell, you've built your own version of the Email
client, and now you're trying to test it.

To do this, you have to build both the client application and the test
package.

In general, to build a test package for an application you have to be
able to build both of them from source. The test package and the
application have to be signed with the same key, as a security
feature. Once you build them, you need to install them to the device.

Afterwards, you can change the application and re-install it without
having to re-build or re-install the test package, and vice versa. You
still have to use the same key each time.

The process of installing applications and test packages is documented
in the Dev Guide. Go to the Dev Guide tab under Developing and look at
Building and Running and also Testing.

You can certainly run tests as the last part of your build process.
You can't do this easily in Eclipse, but you can do it by modifying
your Ant scripts. You can also run unit tests during a build if you're
testing a unit that doesn't depend on Android. To test something that
needs to run on Android, such as an Activity, you have to build it
into an application and install it on Android before you can test it.

When you say the best way to do it like native Android tests, you
should look at the /tests subdirectory for the Email project. It
should contain unit tests for the client. You can use them as a
starting point for doing your own testing.

elk.

On Feb 11, 7:36 am, Oleg Popenov popenov.o...@gmail.com wrote:
 Thanks for your response!

 But now I have some questions could you please answer?

 1) As I understand it should be built at the same time with the
 platform building. Any specific parameters to build?  After build I
 need to install them? How can I do that?
 2) Is there any way to run tests during building? Is it possible to
 abort building if any tests failed?

 I made some changes in Adndroid platform and I need to test them. I
 think the best way to do it like native Android tests.

 Appreciate any help.
 Most sincerely, Oleg

 On Feb 10, 6:32 pm, Diego Torres Milano dtmil...@gmail.com wrote:







  If

  $  adb shell pm list instrumentation

  output is empty, then you don't have any test installed.
  Install them first.

  On Feb 9, 8:44 am, Oleg Popenov popenov.o...@gmail.com wrote:

   Hi,

   I've tried to run Instrumentation Tests on device from adb shell and I 
   get a
   strange error, could you please help me?
   If I run tests for any internal android application (email for example) as
   it written in AndroidManifest.xml,

   * !--*
   * This declares that this app uses the instrumentation test runner 
   targeting
   *
   * the package of com.android.email.  To run the tests use the command:*
   * adb shell am instrument -w
   com.android.email.tests/android.test.InstrumentationTestRunner*
   * --*

   then I get an error:

   *am instrument -w
   com.android.email.tests/android.test.InstrumentationTestRunner
   **INSTRUMENTATION_STATUS: id=ActivityManagerService
   **INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for:
   Component
   **Info{com.android.email.tests/android.test.InstrumentationTestRunner}
   **INSTRUMENTATION_STATUS_CODE: -1
   **android.util.AndroidException: INSTRUMENTATION_FAILED:
   com.android.email.tests/a*
   *ndroid.test.InstrumentationTestRunner*

    *
   *
   The result of the command *'pm list instrumentation' *is empty.
   How can I run tests?

   Thanks in advance!
   Most sincerely, Oleg

  --
  Have you read my blog ?http://dtmilano.blogspot.com
  android junit tests ui linux cult thin clients

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Please give us the samples

2011-02-11 Thread A. Elk
I've often seen this error on Windows 7. I blame Windows. What's
happening is that the SDK manager is trying to
download the zip file to a temp directory, but it doesn't have write
access to the directory. In turn, this is because permissions
enforcement in Windows 7 is draconian. Unless one is the top level
administrator for the machine, one doesn't have write access to C:
\Program Files (x86). One has *installation* access but not write
access.

The workarounds are:
- if you're the top level administrator, give yourself write access to
the highest-level directory you can.
- if you're not, try giving yourself access to C:\Program Files
(x86)\Android\android-sdk-windows and its subdirectories. You can do
this by right-clicking on the directory folder, selecting Properties,
and then selecting the Security tab. You'll probably see that the
folder is set to be read-only. Unset that and try the operation
again. Unfortunately, you have to do this for each file you download.
- Get the administrator for your machine to log in to it and install
the SDK for you.

On Feb 3, 10:19 pm, alainr345 alainr...@gmail.com wrote:
 I followed the instructions and installed JDK6 then Eclipse 3.6 then
 Android SDK 9 then Android APT. That seemed promising until I got to
 the Samples step. Downloading the Android sample code through the SDK
 manager (and there is no other way on Windows) does NOT work (not on
 Windows 7 at least); the messasge is:

 Downloading Samples for SDK API 9, revision 1
 File not found: C:\Program Files (x86)\Android\android-sdk-windows\temp
 \samples-2.3_r01-linux.zip (Access is denied)

 Or similar with all the other versions, Personally, I won't follow the
 individual links to each sample, it's too cumbersome. So could you get
 your act together please  folks...
 A.R.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: startActivity() in monkeyrunnner doesn't work

2011-02-11 Thread A. Elk
It looks as if your component name is incomplete. It looks as if you
provided a Java package name, but not the Android package name for
your application.

A component name is not a path to the application, nor is it an
Android package name or a Java package ID. It *looks like* a Java
package ID, because Android chose to use that form as a way of
uniquely identifying application packages.
Though this is confusing, it does make sense. Just as it's easy to
build a unique URI just by using a name that's unique to you, so is it
easy to build a unique Java package ID or Android package name.

I prefer to use Java package ID to refer to the string that comes
after an import statement, and Android package name to refer to the
value of the package attribute in the manifest element of
AndroidManifest.xml. They have the same syntax, but they mean
different things.
The Java ID is a fully-qualified class identifier; the package name is
a unique identifier for your *application*.

The component parameter to startActivity has to be the fully-
qualified name of an Android Activity in your application. Fully-
qualified means that it has to contain the package name for your
application and the fully-qualified class name for your Activity.
The form is

packagename + / + activityname.

For example, if your packagename (the value of the package
attribute of the manifest element in your AndroidManifest.xml) is
com.example.test.application and
your main Activity class name MainActivity in the Java package
com.example.myapp then the component name is

com.example.test.application/com.example.myapp.MainActivity

Component names are not discussed all that much in Android, but
they're very important, since they are a complete and unique
identifier for an Android component (Activity, content provider, etc.)
in the system.

If you want to learn a bit more, look at the javadoc for
android.content.ComponentName.

kle.

On Feb 4, 4:23 pm, RonQ ronquin...@gmail.com wrote:
 Good information.  Thanks.  I'm not using a specific notepad example
 to launch my app.  Instead I'm using our own internal app.  I have
 access to the code, but how do you know what path to provide to the
 application?  I've tried some that I thought would work, such as our
 SplashScreen, but my app never comes up.  It does the navigation on
 the device, but just without my app running.  I just navigates though
 my phone menu.

 I'm making the same call like this
 device.startActivity(component='com.myapp.SplashScreen')

 How does one know what can actually be called with the startActivity
 component call?  Any help would be appreciated.

 On Jan 11, 10:30 pm, Hakbong Kim haknal...@gmail.com







 haknal...@gmail.com wrote:
  Your code works.
  Thanks for your help.

  On 1월7일, 오전6시10분, A. Elk lancaster.dambust...@gmail.com wrote:

   Uh, I think the beginning example in theMonkeyRunnerdocumentation is
   wrong. The initial snippet is very misleading. Someone should report
   that as a bug.

   Your code listing doesn't show that you installed the package that
   contains the component you want to start. I assume that you either
   installed it before you ranMonkeyRunner, or that you left this out of
   your listing.

   The syntax of the component parameter is the same as that for an
   Android ComponentName: package_name/class_name. Package_name is the
   Android package name of the .apk containing your application. In your
   example, assuming that you're using the Note Pad sample app as your
   application, it's com.example.android.notepad. Class_name is the name
   of a class that Android can start; it's almost always an extension of
   android.app.Activity. For the Note Pad sample app, you would probably
   use com.example.android.notepad.NotesList.

   To ensure you're not doing something wrong, remember to install the
   package, then try using this code snippet:

   packagename = com.example.android.notepad
   classname = com.example.android.notepad.NotesList
   componentname = packagename + / + classname
   device.StartActivity(component=componentname)

   On Jan 6, 12:28 am, Hakbong Kim haknal...@gmail.com

   haknal...@gmail.com wrote:
I tried to usemonkeyrunner.
A target is Android vmware image.
I checked that press(), takeSnopshot() and drag() are normally
executed.
But, startActivity() is not executed.

The first source code is

     from com.android.monkeyrunnerimportMonkeyRunner, MonkeyDevice
     device =MonkeyRunner.waitForConnection()

device.startActivity(component='com.example.android.notepad.NotesList')

The second is
( I modified a third line referring to a writing of this group )

     from com.android.monkeyrunnerimportMonkeyRunner, MonkeyDevice
     device =MonkeyRunner.waitForConnection()
     device.startActivity(component='com.example.android.notepad
\.NotesList')

In two cases, the result is same

110106 17:13:42.168:I [main] [com.android.monkeyrunner.MonkeyManager

[android-developers] Re: ServiceTestCase and Contexts

2011-02-04 Thread A. Elk
Hmmm.

ServiceTestCase.getSystemContext() returns the context of the test
package. ServiceTestCase.getApplication() gets the Application
instance in use by the service under test. It's probably better to use
that Application object to look at the assets you want.

When you wrote getContext(), I didn't understand which class you were
talking about. In a test case class, calling getContext() will usually
default to AndroidTestCase.getContext(), which will give you the
context of the test package. In an instrumented test case like
ActivityInstrumentationTestCase2, you have an Instrumentation object,
so you can call getTargetContext() on that object to get the context
of the instrumented component under test.

To come back to the original problem, which assets do you need to use?
Could you build them into your test package as well as the application
under test, instead of trying to get them from the app on the fly?

On Feb 4, 11:20 am, nate nat...@cisco.com wrote:
 OK, I found a solution:

 I created a context to our test package and was able to access the
 assets:

 mTestAppContext = getContext().createPackageContext(com.blah.test,
 Context.CONTEXT_IGNORE_SECURITY);

 Just in case anyone else needs a workaround.

 On Feb 4, 10:36 am, nate nat...@cisco.com wrote:







  Also, i put the test assets in the target project's directory and was
  able to access them with:

  getSystemContext().getAssets().list(.)

  On Feb 4, 10:31 am, nate nroy...@gmail.com wrote:

   I checked my setUp() method and I do call super.setUp() as the first
   line.  The reason I believe the contexts are the same are two-fold:

   I tried both:

   getSystemContext().getAssets().list(.)
   getContext().getAssets().open(.);

   and neither of them listed any files.  The second reason is that I
   read the code for ServiceTestCase and saw that the getSystemContext()
   is just the
   same context retrieved by getContext(), but it's grabbed before any
   tests have a chance to mess with it(according to the comment in the
   code):

   @Override
       protected void setUp() throws Exception {
           super.setUp();

           // get the real context, before the individual tests have a
   chance to muck with it
           mSystemContext = getContext();

       }

   So it would seem that getting the context to the app the testcase is
   in is not possible with the ServiceTestCase, unless I am missing
   something.

   On Feb 3, 9:15 pm, A. Elk lancaster.dambust...@gmail.com wrote:

What leads you to believe that both Context objects contain the same
information? If you do a getSystemContext() you should get the context
that's stored during setUp(). The only thing that might screw this up
is if you overrode setUp() but forgot to call super.setUp() first.

On Feb 2, 2:08 pm, nate nroy...@gmail.com wrote:

 Hey Everyone,
    I don't know if I am doing something wrong here, but when I am
 trying to use the ServiceTestCase class to test my Service, I cannot
 get a context which points to the test project.  getContext() and
 getSystemContext() both seem to point to the target project's
 context.  The reason I need the context of my test app is that i have
 some assets which i need to be able to use in order to test the
 service in question.  Does anyone know of a workaround or could point
 me at a way of resolving this?  (i looked through the source of
 ServiceTestCase and didn't see another way)

 Something similar to instrumentationtestcase's
 getInstrumentation.getContext() is what I am looking for.

 Thanks.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: ServiceTestCase and Contexts

2011-02-03 Thread A. Elk
What leads you to believe that both Context objects contain the same
information? If you do a getSystemContext() you should get the context
that's stored during setUp(). The only thing that might screw this up
is if you overrode setUp() but forgot to call super.setUp() first.

On Feb 2, 2:08 pm, nate nroy...@gmail.com wrote:
 Hey Everyone,
    I don't know if I am doing something wrong here, but when I am
 trying to use the ServiceTestCase class to test my Service, I cannot
 get a context which points to the test project.  getContext() and
 getSystemContext() both seem to point to the target project's
 context.  The reason I need the context of my test app is that i have
 some assets which i need to be able to use in order to test the
 service in question.  Does anyone know of a workaround or could point
 me at a way of resolving this?  (i looked through the source of
 ServiceTestCase and didn't see another way)

 Something similar to instrumentationtestcase's
 getInstrumentation.getContext() is what I am looking for.

 Thanks.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Whats the key difference between Monkey Runner and Monkey tool?

2011-02-02 Thread A. Elk
You can send keystrokes and touch events with the MonkeyRunner API.
It's available in AOSP and Android 2.3, and documented in Android 2.3.

On Feb 1, 9:51 pm, Bharathi raja bharathiraja.andr...@gmail.com
wrote:
 Hi,

 Can you please tell me it required any module\lib files to write python
 script to do keystrokes and touch event.
 if so, from where i will get those module files

 On Mon, Jan 31, 2011 at 10:45 PM, A. Elk 
 lancaster.dambust...@gmail.comwrote:







  You might use Monkey to test that your app handles only certain
  keystrokes, handles only keystrokes sent in a certain order, and
  doesn't crash if it gets anything else. For touch events, you could
  use it to test that random touches or gestures don't do something
  unexpected in your application. As the Dev Guide topic says, Monkey is
  for stress-testing your application.

  MonkeyRunner provides limited scripting and control capabilities, so
  that you can write Python scripts to run test suites. The Froyo Dev
  Guide describes MonkeyRunner in some detail. You have to know Python
  in order to use it. You can send keystrokes and touch events to
  control the UI, but to send touch events you have to know the screen
  coordinates where you want the touch to occur. That means that you'll
  need to do some work by hand first, to figure out those coordinates.
  As far as I know, MonkeyRunner can't do gestures.

  Robotium is in Java only. It's like JUnit. You write something that
  looks like a Java program. The Robotium runner interprets it as a
  sequence of steps to run. There's documentation online; you should
  Google Robotium.

  Suspend/restart could mean many things. You may or may not be able to
  test those functions automatically. In general, you can't easily test
  something that requires turning off the device.

  File copying from the network could be done in MonkeyRunner. It really
  depends on what you're trying to do. Since MonkeyRunner is essentially
  a Python module, you can write any Python program you want and add
  MonkeyRunner to it. Python can do just about anything you can think
  of.

  Python can accept user input.

  Unfortunately, I don't have the time to teach you Python or Java. This
  forum really isn't appropriate for that.

  On Jan 31, 2:29 am, raki rakeshkart...@gmail.com wrote:
   Hi Alk,

   Thanks a lot for the reply.
   I had a look at Robotium. It seems it will solve my purpose.

   But I am still not clear on whats the difference between Monkey ad
   Monkey runner. Can u please give a simple scenario explaining thier
   main purpose and difference between each other?

   I would be grateful to you if you clarify the below questions as well?

   1) To work with Robotium do I need to have knowledge on Java or can I
   manage with Python itself?
   2) Power management processes like suspend/restart is a key part in
   our testing. Can I achieve it using Monkey runner or Robotium?
   3) Can we automate the operations like file copy through network using
   Monkey runner/Python?
   4) I would like to create scripts that accept inputs from user while
   running. I have no knowledge on Python. Hope I can achieve it in
   Python. Correct me if I am wrong.

   Thanks in advance.

   Rakesh

   On Jan 31, 2:40 am, A. Elk lancaster.dambust...@gmail.com wrote:

I don't think that Monkey will give you the type of UI testing you
want. It's mostly used to generate input while you test other things.

MonkeyRunner can do functional testing, but a better use for it is to
run suites of system tests and then collect the results. Remember,
too, that MonkeyRunner is an API, not a program; you have to write a
Python program to use it.

You may also want to look at Robotium, which is similar to Selenium
but with specific support for Android.

UI

On Jan 28, 12:06 am, raki rakeshkart...@gmail.com wrote:

 Hi,

 I want to automate UI and functional testing on Android OS.

 I am in dilemma whether to use Monkey or Mokeyrunner for the purpose.

 I will not be able to access the source code for the applications but
 I just need to test the applications, probably using Python/Shell
 scripting.

 Can anyone suggest me which tool I need to use for best results?

 I also want to include power management operations in between my UI
 testing processes.

 Any suggestions are greatly appreciated.

 Thanks,
 Rakesh

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.comandroid-developers%2Bunsubs 
  cr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group

[android-developers] Re: Whats the key difference between Monkey Runner and Monkey tool?

2011-01-31 Thread A. Elk
You might use Monkey to test that your app handles only certain
keystrokes, handles only keystrokes sent in a certain order, and
doesn't crash if it gets anything else. For touch events, you could
use it to test that random touches or gestures don't do something
unexpected in your application. As the Dev Guide topic says, Monkey is
for stress-testing your application.

MonkeyRunner provides limited scripting and control capabilities, so
that you can write Python scripts to run test suites. The Froyo Dev
Guide describes MonkeyRunner in some detail. You have to know Python
in order to use it. You can send keystrokes and touch events to
control the UI, but to send touch events you have to know the screen
coordinates where you want the touch to occur. That means that you'll
need to do some work by hand first, to figure out those coordinates.
As far as I know, MonkeyRunner can't do gestures.

Robotium is in Java only. It's like JUnit. You write something that
looks like a Java program. The Robotium runner interprets it as a
sequence of steps to run. There's documentation online; you should
Google Robotium.

Suspend/restart could mean many things. You may or may not be able to
test those functions automatically. In general, you can't easily test
something that requires turning off the device.

File copying from the network could be done in MonkeyRunner. It really
depends on what you're trying to do. Since MonkeyRunner is essentially
a Python module, you can write any Python program you want and add
MonkeyRunner to it. Python can do just about anything you can think
of.

Python can accept user input.

Unfortunately, I don't have the time to teach you Python or Java. This
forum really isn't appropriate for that.

On Jan 31, 2:29 am, raki rakeshkart...@gmail.com wrote:
 Hi Alk,

 Thanks a lot for the reply.
 I had a look at Robotium. It seems it will solve my purpose.

 But I am still not clear on whats the difference between Monkey ad
 Monkey runner. Can u please give a simple scenario explaining thier
 main purpose and difference between each other?

 I would be grateful to you if you clarify the below questions as well?

 1) To work with Robotium do I need to have knowledge on Java or can I
 manage with Python itself?
 2) Power management processes like suspend/restart is a key part in
 our testing. Can I achieve it using Monkey runner or Robotium?
 3) Can we automate the operations like file copy through network using
 Monkey runner/Python?
 4) I would like to create scripts that accept inputs from user while
 running. I have no knowledge on Python. Hope I can achieve it in
 Python. Correct me if I am wrong.

 Thanks in advance.

 Rakesh

 On Jan 31, 2:40 am, A. Elk lancaster.dambust...@gmail.com wrote:







  I don't think that Monkey will give you the type of UI testing you
  want. It's mostly used to generate input while you test other things.

  MonkeyRunner can do functional testing, but a better use for it is to
  run suites of system tests and then collect the results. Remember,
  too, that MonkeyRunner is an API, not a program; you have to write a
  Python program to use it.

  You may also want to look at Robotium, which is similar to Selenium
  but with specific support for Android.

  UI

  On Jan 28, 12:06 am, raki rakeshkart...@gmail.com wrote:

   Hi,

   I want to automate UI and functional testing on Android OS.

   I am in dilemma whether to use Monkey or Mokeyrunner for the purpose.

   I will not be able to access the source code for the applications but
   I just need to test the applications, probably using Python/Shell
   scripting.

   Can anyone suggest me which tool I need to use for best results?

   I also want to include power management operations in between my UI
   testing processes.

   Any suggestions are greatly appreciated.

   Thanks,
   Rakesh

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Whats the key difference between Monkey Runner and Monkey tool?

2011-01-30 Thread A. Elk
I don't think that Monkey will give you the type of UI testing you
want. It's mostly used to generate input while you test other things.

MonkeyRunner can do functional testing, but a better use for it is to
run suites of system tests and then collect the results. Remember,
too, that MonkeyRunner is an API, not a program; you have to write a
Python program to use it.

You may also want to look at Robotium, which is similar to Selenium
but with specific support for Android.

UI

On Jan 28, 12:06 am, raki rakeshkart...@gmail.com wrote:
 Hi,

 I want to automate UI and functional testing on Android OS.

 I am in dilemma whether to use Monkey or Mokeyrunner for the purpose.

 I will not be able to access the source code for the applications but
 I just need to test the applications, probably using Python/Shell
 scripting.

 Can anyone suggest me which tool I need to use for best results?

 I also want to include power management operations in between my UI
 testing processes.

 Any suggestions are greatly appreciated.

 Thanks,
 Rakesh

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: When to use SingleLaunchActivityTestCase

2011-01-30 Thread A. Elk
First of all, yes, you can organize multiple tests into one test
method, but that's not the accepted way of doing unit/functional
testing. That's why you should use
ActivityInstrumentationTestCase2(AITC2) in *most* cases to do unit/
functional testing of multiple methods in an Activity or multiple
pathways through it. Having a clean fixture (from setUp() and
tearDown()) for every test you do is the only safe way to ensure
you're testing what you *think* you're testing.

As you say, you definitely need to use if you expect your Activity to
handle different Intents. You can only set up the Intent in advance if
you use AITC2.

As you say, SingleLaunchActivityTestCase(SLATC) is primarily for
situations where you want to simulate a non-standard mode. The three
non-standard modes share a characteristic that, depending on the
circumstances, there will only be a single instance of the Activity.
SLATC forces a single instance for multiple test methods. You can use
it to either do multiple different tests on the same instance, or run
the same test multiple times.

Hope this helps.

elk elk elk

On Jan 26, 10:04 pm, Peter12 peterisgood2...@gmail.com wrote:
 I have studied the android test framework recently and have some
 questions about the differences between
 ActivityInstrumentationTestCase2 and SingleLaunchActivityTestCase test
 case classes.
 I know the difference in definition.
 ActivityInstrumentationTestCase2 class is used in functional testing
 and can let developer to mock intent. This is an important feature for
 activity which may deal with multiple intents.
 SingleLaunchActivityTestCase class is for testing an activity which
 does not change from test to test because it set up and tear down once
 and can test the activity handles multiple calls correctly.
 However, in my opinion, we also can organize multiple calls into one
 method and use ActivityInstrumentationTestCase2 class for this kind of
 test.
 Does anyone know about some scenarios which
 SingleLaunchActivityTestCase should adopt rather than
 ActivityInstrumentationTestCase2?
 By the way, in android Dev document, it said that
 “SingleLaunchActivityTestCase test case is useful for testing an
 activity that runs in a mode other than standard. “, which means we
 can use it in the other modes such as singleTop, singleTask, and
 singleInstance.
 Why is SingleLaunchActivityTestCase suitable for these three modes? Is
 it because SingleLaunchActivityTestCase class launches activity once
 so it can simulate these modes?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Can't see my view structure by HierarchyViewer

2011-01-27 Thread A. Elk
What fails?

Hierarchyviewer is only allowed to run on phones that have a userdebug
build on them. That includes developer phones. My guess is that it
doesn't include whatever you did to your version of Android to root
it.

elk.

On Jan 25, 4:54 pm, Alfie jhwen0...@gmail.com wrote:
 Hi, all
 I've been using HierarchyViewer to see view structure of emulator, and
 tried to test on actual phone device. However, I tried around 4 phones
 (rooted and debug mode) and fails 3 of them. Really have no idea why
 it happens??!!

 Anyone has the suggestion to fix it? Thanks so much

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Integration testing with mock content providers

2011-01-24 Thread A. Elk
Have you tried using Robotium? It looks like the blog you're citing is
using a unit/functional test case class to do higher-level functional
testing of the content provider, and that's not what the Android test
cases are designed for. Robotium can run through a sequence of steps
to do a functional test, if what you want to do is test the Activity
and its relationship to the content provider.

Keep in mind that I know nothing about your app, but *in general* I
would test an app by unit testing its individual POJOs (Plain Ol' Java
Obejcts), then its Android components (Activity, ContentProvider, and
so forth) using the unit/functional tests, and then its end-to-end
functionality using Robotium or similar.

I call the test cases like ActivityInstrumentationTestCase2 unit/
functional tests because they're designed to do JUnit-style tests on a
class (each test is one path through one method), but they require
external non-injectable dependencies (they have to run in the Android
system) that violate strict unit test standards. They also take longer
to run, which is also a unit test no-no.

On Jan 22, 11:52 pm, Ian ian.fawcett.hun...@gmail.com wrote:
 I've got an Activity which uses the Contact DB, and I'm looking to
 auto-test this. I see several solutions in the past, but one (http://
 dtmilano.blogspot.com/2009/12/android-testing-contentprovider.html)
 provides a link to 'android-mock' which links to a commercial site,
 and another (by Tenacious33) is out of date.

 Can anybody help me get android-mock, or is there an even better
 alternative?

 Many Thanks
 Ian Hunter

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Problem running Android JUnit Test on eclipse

2011-01-24 Thread A. Elk
I'm almost certain it's ADT. All that the ADT tools do is run the
command-line tools in the background and then format the output.

When I change ADT versions, I first *uninstall* the old ADT tools,
restart Eclipse, install the new ADT tools, and then restart again. I
always use the ADT tools for the platform level I'm building against.
I've found that 9 times out of 10, strange behavior in Eclipse is due
to having the wrong version of ADT.

On Jan 21, 5:06 pm, gaurav grv...@gmail.com wrote:
 Here are the answers:

 1. I have put my application inside the system apps myfroyoDir/
 packages/apps folder and built it using command line. And running the
 emulator and app from command prompt.

 2. Yes both app and test package works fine from command prompt.

 3. Yes I am running my test package with
 android.test.InstrumentationTestRunner.  I tried to use ADT 8.0.1 as
 well as 9.0.0, no luck.

 I did reinstallation of ADT with 2 different version. Tried using
 different versions of eclipse.  Only thing now I can do is to use
 different versions of Android SDK.

 On Jan 21, 4:48 pm, A. Elk lancaster.dambust...@gmail.com wrote:







  Can you please confirm the following:
  - The application under test (not the test package) works fine in
  Eclipse?
  - Both the application under test and the test package work fine from
  the command line?
  - You've followed the directions for setting up a test package in
  Eclipse? See Dev Guide  Developing  Testing  In Eclipse with ADT?

  What test case class are you extending in your test package? Are you
  running your test package with android.test.InstrumentationTestRunner?

  The message suggests that the problem is in ADT, not anywhere else.
  The version of ADT you use has to be compatible with the SDK you're
  using. I usually un-install the ADT and re-install the new version
  when I'm upgrading an SDK.

  Elk? What Elk?

  On Jan 21, 4:40 pm, gaurav grv...@gmail.com wrote:

   I have configured the Froyo source code in eclipse. I am trying to run
   android junit test Run as- Android JUnit Test, a error pop-up
   comes.
   When i try to run the already existing Android Junit Test cases or my
   own test case (compiled with froyo source), I get following error.
   Test runs fine when I run it from command prompt.

   I guess this is ADT related issue, but don't have any solution. I
   tried it on Eclipse galileo and helios, tried ADT 8.0.. and 9.0.0,
   Java version 1.5 and 1.6...nothing worked.

   Please help

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Problem running Android JUnit Test on eclipse

2011-01-21 Thread A. Elk
Can you please confirm the following:
- The application under test (not the test package) works fine in
Eclipse?
- Both the application under test and the test package work fine from
the command line?
- You've followed the directions for setting up a test package in
Eclipse? See Dev Guide  Developing  Testing  In Eclipse with ADT?

What test case class are you extending in your test package? Are you
running your test package with android.test.InstrumentationTestRunner?

The message suggests that the problem is in ADT, not anywhere else.
The version of ADT you use has to be compatible with the SDK you're
using. I usually un-install the ADT and re-install the new version
when I'm upgrading an SDK.

Elk? What Elk?

On Jan 21, 4:40 pm, gaurav grv...@gmail.com wrote:
 I have configured the Froyo source code in eclipse. I am trying to run
 android junit test Run as- Android JUnit Test, a error pop-up
 comes.
 When i try to run the already existing Android Junit Test cases or my
 own test case (compiled with froyo source), I get following error.
 Test runs fine when I run it from command prompt.

 I guess this is ADT related issue, but don't have any solution. I
 tried it on Eclipse galileo and helios, tried ADT 8.0.. and 9.0.0,
 Java version 1.5 and 1.6...nothing worked.

 Please help

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Isolated database tests

2011-01-19 Thread A. Elk
Try RenamingDelegatingContext. It uses a normal Context for most
stuff, but allows you to prefix file and database names to avoid
munging your production stuff.

Elk!

On Jan 19, 7:16 am, Mattias Svala thebra...@gmail.com wrote:
 Hello!

 I would like to be able to write tests for my database code and have them
 run without touching the database that my actual application uses. It would
 be OK for the database tests to start with an empty or non existing database
 each time the tests are run.

 Is this possible?

 I would have guessed that I could use IsolatedContext in some way to achieve
 this, but I have not been able to figure out how. Perhaps there is some
 other way to have my database tests run isolated from the application's
 database?

 :.:: mattias

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: InstrumentationTestRunner with Annotation

2011-01-18 Thread A. Elk
I assume you mean this part of the documentation of
InstrumentationTestRunner:

Filter test run to tests with given annotation: adb shell am
instrument -w -e annotation com.android.foo.MyAnnotation
com.android.foo/android.test.InstrumentationTestRunner

If used with other options, the resulting test run will contain the
union of the two options. e.g. -e size large -e annotation
com.android.foo.MyAnnotation will run only tests with both the
LargeTest and com.android.foo.MyAnnotation annotations.

Filter test run to tests without given annotation: adb shell am
instrument -w -e notAnnotation com.android.foo.MyAnnotation
com.android.foo/android.test.InstrumentationTestRunner

?

On Jan 16, 10:47 pm, Aman Bhardwaj aman.bhard...@gmail.com wrote:
 Cool, thanks for the confirmation.
 In that case I will write and derive derive my runner from
 InstrumentationTestRunner.
 Also Google's documentation is wrong in this case.

 On Sat, Jan 15, 2011 at 6:58 PM, A. Elk lancaster.dambust...@gmail.comwrote:







  Exactly. The annotations in InstrumentationTestRunner come from
  android.test.suitebuilder.annotation. My understanding is that, while
  they're public, they're not supported.

  As a note, InstrumentationTestRunner and the Android unit/functional
  test framework are based on JUnit 3, not JUnit 4.

  On Jan 14, 3:09 pm, Diego Torres Milano dtmil...@gmail.com wrote:
   If you want to provide a different behavior for the test runner just
   create your own extending it:

   public class MyTestRunner extends
   android.test.InstrumentationTestRunner {
     // do wathever you want

   }

   To do whatever you want, use android.test.InstrumentationTestRunner
   source as a an inspiration.

   On Jan 13, 1:47 am, Aman Bhardwaj myama...@gmail.com wrote:

Hi,
I have some test cases with my own defined Annotations, but
InstrumenationTestRunner doesn't runs tests based on annotation.
However it works if I add annotations
from android.test.suitebuilder.annotation.

Is it only supposed to work with annotations
in android.test.suitebuilder.annotation.Smoke?
Any suggestions how to make it work with my own annotations.

Thanks,
~Aman

   --
   Have you read my blog ?http://dtmilano.blogspot.com
   android junit tests ui linux cult thin clients

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.comandroid-developers%2Bunsubs 
  cr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: InstrumentationTestRunner with Annotation

2011-01-15 Thread A. Elk
Exactly. The annotations in InstrumentationTestRunner come from
android.test.suitebuilder.annotation. My understanding is that, while
they're public, they're not supported.

As a note, InstrumentationTestRunner and the Android unit/functional
test framework are based on JUnit 3, not JUnit 4.

On Jan 14, 3:09 pm, Diego Torres Milano dtmil...@gmail.com wrote:
 If you want to provide a different behavior for the test runner just
 create your own extending it:

 public class MyTestRunner extends
 android.test.InstrumentationTestRunner {
   // do wathever you want

 }

 To do whatever you want, use android.test.InstrumentationTestRunner
 source as a an inspiration.

 On Jan 13, 1:47 am, Aman Bhardwaj myama...@gmail.com wrote:

  Hi,
  I have some test cases with my own defined Annotations, but
  InstrumenationTestRunner doesn't runs tests based on annotation.
  However it works if I add annotations
  from android.test.suitebuilder.annotation.

  Is it only supposed to work with annotations
  in android.test.suitebuilder.annotation.Smoke?
  Any suggestions how to make it work with my own annotations.

  Thanks,
  ~Aman

 --
 Have you read my blog ?http://dtmilano.blogspot.com
 android junit tests ui linux cult thin clients

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: IsolatedContext and AndroidTestCase.getContext()

2011-01-10 Thread A. Elk
AndroidTestCase.getContext() returns a normal Context object. It's the
Context of the test case, not the component under test.

IsolatedContext returns a mock Context. I put mock in quotes
because its not a mock in the normal sense of that term (for testing).
Instead, it's a template Context that you have to set up yourself. It
isolates you from the running Android system, so that your Context
or your test doesn't accidentally get outside of the test fixture. For
example, an IsolatedContext won't accidentally hit a production
database (unless you set it up to do that!) Note, however, that some
of the methods in an IsolatedContext may throw exceptions.
IsolatedContext is documented in the Developer Guide under Framework
Topics  Testing, both in Testing Fundamentals and in Content Provider
Testing.

You haven't said anything more about what you're trying to test, but I
find it interesting that you're using AndroidTestCase instead of one
of the more specific classes. Any reason for this?

Elkmeister.

On Jan 9, 11:56 pm, Mattias Svala thebra...@gmail.com wrote:
 Hello!

 I'm writing some tests to test my database code. Can someone here explain if
 there would be a difference writing those tests using the context I get from
 AndroidTestCase.getContext() or using an IsolatedContext.

 Speaking of IsolatedContext, what is the easiest way to create one if I just
 need it for some sqlite database testing?

 Regards,
 Mattias

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: startActivity() in monkeyrunnner doesn't work

2011-01-06 Thread A. Elk
Uh, I think the beginning example in the MonkeyRunner documentation is
wrong. The initial snippet is very misleading. Someone should report
that as a bug.

Your code listing doesn't show that you installed the package that
contains the component you want to start. I assume that you either
installed it before you ran MonkeyRunner, or that you left this out of
your listing.

The syntax of the component parameter is the same as that for an
Android ComponentName: package_name/class_name. Package_name is the
Android package name of the .apk containing your application. In your
example, assuming that you're using the Note Pad sample app as your
application, it's com.example.android.notepad. Class_name is the name
of a class that Android can start; it's almost always an extension of
android.app.Activity. For the Note Pad sample app, you would probably
use com.example.android.notepad.NotesList.

To ensure you're not doing something wrong, remember to install the
package, then try using this code snippet:

packagename = com.example.android.notepad
classname = com.example.android.notepad.NotesList
componentname = packagename + / + classname
device.StartActivity(component=componentname)



On Jan 6, 12:28 am, Hakbong Kim haknal...@gmail.com
haknal...@gmail.com wrote:
 I tried to use monkeyrunner.
 A target is Android vmware image.
 I checked that press(), takeSnopshot() and drag() are normally
 executed.
 But, startActivity() is not executed.

 The first source code is

      from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
      device = MonkeyRunner.waitForConnection()

 device.startActivity(component='com.example.android.notepad.NotesList')

 The second is
 ( I modified a third line referring to a writing of this group )

      from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
      device = MonkeyRunner.waitForConnection()
      device.startActivity(component='com.example.android.notepad
 \.NotesList')

 In two cases, the result is same

 110106 17:13:42.168:I [main] [com.android.monkeyrunner.MonkeyManager]
 Monkey Command: wake.
 110106 17:13:42.310:I [main] [com.android.monkeyrunner.MonkeyManager]
 Monkey Command: quit.

 I tried using startActivity() with other activities. But, the result
 is same.
 What is right arguments for startActivity() ?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] MonkeyRunner

2010-12-21 Thread A. Elk
Just as a note:

The documentation for the Android 2.3 SDK is now online at
developer.android.com. It is also one of the packages available for
download through the SDK manager.

This documentation includes documentation for monkeyrunner.

Although monkeyrunner is not part of the Android 2.2 SDK, you can get
monkeyrunner from the Android Open Source Project at
source.developer.com. It probably works with Android 2.2. You're
probably better off upgrading to Android 2.3.

If you have more questions, please read the documentation.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Import monkeyrunner methods in my java application

2010-12-17 Thread A. Elk
As far as I can tell, the monkeyrunner methods aren't designed to be
called outside of Python. Monkeyrunner is a Python API for functional
and integration tests.

You can put your API in a jar file and use it from Python. The 2.3 SDK
has documentation for Monkeyrunner, including the procedure for adding
your own .jar file to the environment.

On Dec 17, 12:49 am, Miguel Pellón miguelpel...@gmail.com wrote:
 Hi all,

 I have developed a Java API to interact with some apps I developed
 using adb commands. Since now monkeyrunner is out there, I would like
 to use monkeyrunner methods in my java class. Do you know if this is
 possible? If it is, how can this be done?

 Thanks!

 Regards,
 Miguel

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Unit testing framework with monkeyrunner

2010-12-17 Thread A. Elk
Your question is vague, to me.

If you're asking how to run Android unit tests (classes in
android.test.*) using MonkeyRunner:

Set up your Android tests, then call them from MonkeyRunner. You can,
for example, write a single Python program using the MonkeyRunner API
that goes through a set of emulators, each with its own
configuration,  runs a suite of test cases against each emulator, and
then outputs the results to a file. You can do this because Python
allows you to call the emulator comand-line program programmatically
(see the os module). You use the device.instrument() method to call
an instrumentation for a device, and instrumentation is the way you
run an Android test.

If you're asking how to run a Python unit test using MonkeyRunner,
then it depends on what you're trying to do, but in general, you don't
need to.

If you want to use MonkeyRunner to run JUnit, I would ask why? You
can run JUnit from the command line. Just because you can run JUnit
(or an Android JUnit test) from Eclipse doesn't mean that you *have*
to. The SDK documentation explains this. Look in the Dev Guide under
Developing  Testing  Testing with Other IDEs.

JUnit runs each test method in each test class in a package of test
classes. Similarly, the Android test framework uses instrumentation
plus JUnit to run each test method in each test class in a test
package.

Some more comments about unit testing:

Remember, *unit testing should focus on each test taking a single path
through a single app method.*

Use unit testing to verify that the class you've written works
according to its specifications. Also use unit testing to verify that
the latest change you made hasn't broken anything. Test-driven
development says that your class and methods do what the *tests* say
they do, not what the *code* says they do. What isn't tested not only
doesn't work, it doesn't exist.

In Android, you would do *true* unit testing by doing most of your
functionality in Plain Old Java Objects (POJOs) and then testing these
using JUnit. You would follow this by doing what I like to call
pseudo-unit testing with Android's testing framework, using the test
case classes in android.test.* and InstrumentationTestRunner. This
framework allows you to test objects that require the Android
environment. The documentation for some of them says that they are
unit tests, while others are documented as functional tests. By
the most strict definition they're all functional tests, but the
nature of Android means that you can't do a true unit test on an
object that depends on Android system objects. The reason: you can't
create the Android system objects outside of Android, so you have to
instantiate the object under test within Android, so you have to do a
bit of hand-waving on the dependencies.

Nonetheless, Android tests are more unit test than functional test.
You *can't* do high-level functional testing or integration testing in
the Android framework, because you can't test more than one Android
object at a time. One of them has to be an external dependency that
you must assume is working.

You may decide that a useful way to do functional/integration testing
is to use the Android test framework along with some larger framework.
You write some tests using Android's test case classes. You then run
multiple test cases sequentially to simulate UI interactions,
processing, etc. You can use MonkeyRunner to do this. Perhaps a better
way to do it is to use Robotium or Selenium.



On Dec 17, 12:50 am, Miguel Pellón miguelpel...@gmail.com wrote:
 I would like to use some unit testing for python combined with the
 monkeyrunner, but I have seen monkeyrunner is called via command line,
 so I dont see the way of integrating it into a unit testing framework
 (similar to junit). Any idea on how to do it?

 Thanks!

 Regards,
 Miguel

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Unit Testing Functional Testing

2010-12-15 Thread A. Elk


On Dec 15, 12:39 pm, Etienne lawloretie...@gmail.com wrote:

 How do you go about creating an object with all the dependencies set to
 known values by injection?


Depends on what type of object you're talking about, and what test
case class you're using. ActivityInstrumentationTestCase2 runs in a
real Android environment, so it uses a normal Context object and
interacts with the Activity's UI in a normal way. To ensure you're
using the environment you want, you can modify the Context and set
up a fixture for the test in setUp(). You can't *inject* dependencies,
but you can set up your dependencies to a known state. For example,
you can use setUp() to preload a content provider that your Activity
uses.

A set of POJOs, properly designed, would require minimal or no
external dependencies. My favorite example of such an object is an
ordered collection object. Properly designed, you should be able to
inject a sort algorithm and a comparison algorithm.

 So if i am in the LoginActivity and i want to enter fields into EditText
 views such as a username and password
 and then click a button to login which starts another activity that makes a
 REST call with the appropriate login
 signature and the second activity parses the XML response which is returned
 back to the LoginActivity, is there
 no way of testing that whole process with ActivityInstrumentationTestCase2
 or ActivityUnitTestCase?


In general, you can't test more than one object at a time in a unit
test. You don't *want* to do this. In a unit test, you're testing the
methods in *one* object; everything else is assumed to be working.
Anything that you need to supply to the method under test should
either be atomic (an integer, for example) or a mock object
(something whose state you can easily establish). In the case you
propose, the second Activity either has to be a mock, or you have to
assume it is. If you test LoginActivity, you must assume that the
second Activity is working.

 Also you say that:



 Both ActivityUnitTestCase and ActivityInstrumentationTestCase2 are (IMHO)
 pseudo-unit test
 cases.

 Then what types of tests are appropriate in each class?

I would use ActivityInstrumentationTestCase2. I suspect, although I am
not sure, that ActivityUnitTestCase was provided for the sake of
purity. Since it's isolated from the rest of the Android
environment, you can say that it does a true unit test. I'm not sure
that there's a need for this.

Test-driven development and unit testing require a different and
sometimes orthogonal mindset to traditional OOP development
techniques. Sometimes you have to be strict with yourself. If you find
yourself wanting to control the interaction of two objects in order to
test them, then you have to mock one of them.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Unit Testing Functional Testing

2010-12-14 Thread A. Elk
I'll try to answer your last question first:

You are in Activity A, and you use startActivityForResult to start
Activity B. You handle the result of Activity B in
ActivityA.onActivityResult().

How do you test that the actual result is equal to the expected
result? In general, you test the result of a method by creating the
object with all the dependencies set to known values (the fixture),
preferably by injection. Then you call the method with pre-determined
values. Based on the dependencies as the values, you should be able to
predict the answer. You compare this prediction to the object's actual
answer with an assert().

What I think you're *saying*, though, is How do I create Activity B
(starting it means instantiating an object), find out its result *by
looking inside it*, and then comparing this to the result that comes
back in ActivityA.onActivityResult()? The answer is: you can't.

You can't instrument more than one class at a time in a single Android
test case class, so you can't test more than one Activity at a time.
Neither ActivityUnitTestCase nor ActivityInstrumentationTestCase2 are
designed to test more than one Activity at a time.

This is by design. Both ActivityUnitTestCase and
ActivityInstrumentationTestCase2 are (IMHO) pseudo-unit test
cases.They're both meant to test the methods of one object at a time,
so they're not at the level of Selenium (or it's Android spin-off,
Robotium). On the other hand, they have to run within the Android
environment, so they're not really unit tests. Nevertheless, you
should use the unit test rubric with them: make each test method a
single path through a single Activity method.

To test the interaction between Activities, you probably have to use
Robotium/Selenium or write your own test harness.

On Dec 14, 12:29 am, Etienne lawloretie...@gmail.com wrote:
 I have created an app that sends intents among multiple activities.
 After doing some research i have found that the ActivityUnitTestCase
 class is designed for unit testing while the
 ActivityInstrumentationTestCase2 is designed for functional testing. I
 understand the use of methods such as setUp(), tearDown(), and
 testPreconditions(). However i am having a little difficulty in trying
 to figure out what type of user-defined-tests to create in the previously
 mentioned classes. I know that there are a few methods that cannot be
 called in certain classes.

 To be more specific, if i am in activity A and i click a button then
 it calls startActivityForResult() which starts activity B. I then send
 an intent back to activity A which is handled in the
 onActivityResult() method. How can i test that the actual result in
 onActivityResult() is equal to the expected result?

 Is there some sort of mock dependency for interaction between multiple
 activities?
 And if so how do you create mock dependencies?

 I have been looking extensively for any kind of examples that would
 help clear up this confusion. I have seen the Demo APIs on the
 developer.android.com
 website but they are rather limited.  If anyone could provide any assistance
 i
 would greatly appreciate it.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Setting up a test project issues

2010-12-09 Thread A. Elk
Are you looking at the latest docs for Gingerbread (2.3)?

On Dec 8, 5:32 pm, Etienne Lawlor lawloretie...@gmail.com wrote:
 Thanks for the clarification.  Now it makes much more sense.  The only
 reason to have the /tests subdirectory is to keep all the code in one
 application directory so that porting the code to a repository is easier.
  However, you still need that separate node of a test project to be able to
 run the test project as an Android JUnit Test because of the tools involved.
  Thanks for you help.  This kind of explanation would really help on the
 developer guide website.

 On Wed, Dec 8, 2010 at 4:58 PM, A. Elk lancsaster.dambust...@gmail.comwrote:







  OK, so you now have two projects in Eclipse, MyProject and
  MyProjectTest.

  MyProject's files are in someworkspace/MyProject. From now on, I'll
  just abbreviate this /MyProject.

  MyProjectTest's *files* are in /MyProject/tests. For this reason, you
  have two projects, but one of them has its files completely within the
  other one.

  *Just as a note*, you will see that the Project Explorer node for
  MyProject has sub-nodes for the MyProject files and *also* for the
  MyProjectTest files.

  You should run the tests from MyProjectTest, by selecting the
  MyProjectTest node in Project Explorer, and then right-clicking and
  selecting Run As  Android JUnit Test.

  To say this another way, on your disk you have the following directory
  structure

  /MyProject/
    src/
    gen/
    res/
    tests/
       src/
       gen/
       res/

  *In Eclipse*, the project MyProject is associated with the directory /
  MyProject/. The project MyProjectTest is associated with the
  directory /MyProject/tests.

  The point of having tests/ inside MyProject is to keep the tests near
  the source code they're testing. That way, if you have to move, share,
  backup, restore, or whatever your source files, you're much less
  likely to forget the tests.

  You still need to have two *projects* at the same level in Eclipse
  because you use different tools to run them. You can't run a test
  project as an Android application, and you can't run an Android
  application as a test project. I think that you may want to click some
  button to run one or more tests that you've pre-associated with an
  application project. That is, you'd like a single button associated
  with your application that runs the tests for the application. It's
  certainly possible to do this in Ant, by setting up the proper target.
  It's an interesting idea.

  A. Elk.

  On Dec 8, 2:45 pm, Etienne Lawlor lawloretie...@gmail.com wrote:
   I have already created the test project MyProjectTest which shows up at
  the
   same level of MyProject.  Also when i created that test project there is
  a
   subdirectory /tests which is in the root directory of MyProject.  I dont
  get
   what you mean when you say:

   You need to create an ecliose project for the tests folder and run that
  one

   as an andrdoid instrumentation.

   Could you help clarify this, because i think i have already done this.
    Thanks.

   On Wed, Dec 8, 2010 at 2:16 PM, Xavier Ducrohet x...@android.com
  wrote:
You need to create an ecliose project for the tests folder and run that
  one
as an andrdoid instrumentation.
On Dec 8, 2010 11:51 AM, Etienne Lawlor lawloretie...@gmail.com
  wrote:
 Yes i am using Eclipse. I did all of your steps up to the point where
  you
 said

So, if you used /home/etienne/workspace/MyProject as the location for
your app project, use the location /home/etienne/workspace/MyProject/
tests as the location for your test project.

 When i click finish, then i get an error that says:

 'Refreshing workspace has encountered a problem'
 An internal error occurred during: 'Refreshing workspace'
 Element not found: /MyProject/tests.

 It shows a red x icon on the MyProjectTest project but if i clean the
 project
 then this disappears.

 I do see that now there are two projects: MyProject and
  MyProjectTest.
 In the root directory of MyProject there is a subdirectory /tests.
 In the /tests directory i do see that AndroidManifest.xml file that
  has
an
 instrumentation element which seems to be set up properly.

 I don't understand this part of what you said:

*Even though the tests directory appears in MyProject*, do *not* use
it to create or run tests. This is a weird artifact of Eclipse; you
can create a project as a subdirectory of another project, but you'll
see the second project *inside* the first one.

 So what is the point of the /tests subdirectory if there is a test
project
 at
 the same level as the app project and you can only run that seperate
project
 as an Android JUnit test?

 Also when you say:

If you look in the sample apps, all of them (except one) use the
best practice that is documented.

 I guess the best practice means

[android-developers] Re: Cannot display Hello World per the suggestion of Installing of SDK

2010-12-08 Thread A. Elk
The emulator is slow. It may take a few minutes for the app to appear.
It should show Android_ in fixed pitch font for a while, followed by
ANDROID in fancy graphics. After that, it will show the unlock screen.
Follow the on-screen directions to unlock, and the app should appear
in a few moments.

If this doesn't happen after 10 minutes, then you have a problem.

Elk.

On Dec 7, 8:08 pm, jcheng3305 jcheng3...@gmail.com wrote:
 Hi, Team,

 I am the newer of Android Developer.  I did completed the installation
 of SDK and Eclipse 3.6.1 at my notebook with Window Vista.  Eveything
 seems ok.  However,  I followed the first try per the instruction of
 the program of Hello World - create AVD.  It won't show Hello
 World,  but the general emulator display with Android_ at the
 center.  I checked and cannot find any error indicated.    Please help
 and let me know if anything is wrong or where I should check.

 Your prompt response and advise is highly appreciated.

 Thanks.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Setting up a test project issues

2010-12-08 Thread A. Elk
You have not said how you created the test project.

Reading between the lines, I am guessing that you did it in Eclipse.

To do it correctly, you should first use the New Android Project
wizard in Eclipse to create your app project. In the Contents panel,
in the Location textbox, you can accept the default location. *Write
down the location path*

The last step of the wizard asks you if you want to create a test
project. Say yes. Give it a name that is *different* from the app
project. I usually use appprojectTest. In the Location textbox, do
*not* use the default location. Instead, create a tests/ directory
under the location you used for your app.

So, if you used /home/etienne/workspace/MyProject as the location for
your app project, use the location /home/etienne/workspace/MyProject/
tests as the location for your test project.

This should give you two projects in the Project Explorer, MyProject
and MyProjectTest. You can confirm that your test project is set up
correctly. Look in MyProjectTest, and open AndroidManifest.xml. Look
in the far right-hand tab under the main editor for the
androidmanifest.xml tab. This shows you the raw XML. You should see an
instrumentation element.

Run MyProjectTest as an Android JUnit application.

You should run *MyProjectTest* as an Android JUnit Test.

*Even though the tests directory appears in MyProject*, do *not* use
it to create or run tests. This is a weird artifact of Eclipse; you
can create a project as a subdirectory of another project, but you'll
see the second project *inside* the first one.

Also, the Android Create Test Project wizard default behavior does
*not* use the best practice. Instead, it defaults to creating a
separate test directory at the same level as the app directory. This
isn't a good idea, IMHO. It makes it hard to maintain the relationship
between your app and its tests. If you look in the sample apps, all of
them (except one) use the best practice that is documented.

Joe

On Dec 7, 5:58 pm, Etienne lawloretie...@gmail.com wrote:
 On the developer.android.com website there is a guide to testing
 android that says:

 You can create a test project anywhere in your file system, but the
 best approach is to add the test project so that its root directory
 tests/ is at the same level as the src/ directory of the main
 application's project. This helps you find the tests associated with
 an application. For example, if your application project's root
 directory is MyProject, then you should use the following directory
 structure:

   MyProject/
       AndroidManifest.xml
       res/
           ... (resources for main application)
       src/
           ... (source code for main application) ...
       tests/
           AndroidManifest.xml
           res/
               ... (resources for tests)
           src/
               ... (source code for tests)

 The link to the website 
 is:http://developer.android.com/guide/topics/testing/testing_android.html

 So i took this approach and then tried to Run MyProject as an Android
 JUnit Test.  However when i do this the error message i get says:

 An instrumentation test runner is not specified!

 This would make sense if i didn't have the test manifest file
 AndroidManifest.xml in the tests/ directory but i do have the file
 there.  What could be the issue?  I have been able to create a test
 project that is separate from the main project and run the test
 project as an Android JUnit Test, but i don't get how to add the test
 project so that its root directory tests/ is at the same level as the
 src/ directory of the main application's project.  Does anyone know
 whats going on here, or has anyone been successful in getting this to
 work?  Thanks for any help.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Setting up a test project issues

2010-12-08 Thread A. Elk
OK, so you now have two projects in Eclipse, MyProject and
MyProjectTest.

MyProject's files are in someworkspace/MyProject. From now on, I'll
just abbreviate this /MyProject.

MyProjectTest's *files* are in /MyProject/tests. For this reason, you
have two projects, but one of them has its files completely within the
other one.

*Just as a note*, you will see that the Project Explorer node for
MyProject has sub-nodes for the MyProject files and *also* for the
MyProjectTest files.

You should run the tests from MyProjectTest, by selecting the
MyProjectTest node in Project Explorer, and then right-clicking and
selecting Run As  Android JUnit Test.

To say this another way, on your disk you have the following directory
structure

/MyProject/
   src/
   gen/
   res/
   tests/
  src/
  gen/
  res/

*In Eclipse*, the project MyProject is associated with the directory /
MyProject/. The project MyProjectTest is associated with the
directory /MyProject/tests.

The point of having tests/ inside MyProject is to keep the tests near
the source code they're testing. That way, if you have to move, share,
backup, restore, or whatever your source files, you're much less
likely to forget the tests.

You still need to have two *projects* at the same level in Eclipse
because you use different tools to run them. You can't run a test
project as an Android application, and you can't run an Android
application as a test project. I think that you may want to click some
button to run one or more tests that you've pre-associated with an
application project. That is, you'd like a single button associated
with your application that runs the tests for the application. It's
certainly possible to do this in Ant, by setting up the proper target.
It's an interesting idea.

A. Elk.


On Dec 8, 2:45 pm, Etienne Lawlor lawloretie...@gmail.com wrote:
 I have already created the test project MyProjectTest which shows up at the
 same level of MyProject.  Also when i created that test project there is a
 subdirectory /tests which is in the root directory of MyProject.  I dont get
 what you mean when you say:

 You need to create an ecliose project for the tests folder and run that one

 as an andrdoid instrumentation.

 Could you help clarify this, because i think i have already done this.
  Thanks.







 On Wed, Dec 8, 2010 at 2:16 PM, Xavier Ducrohet x...@android.com wrote:
  You need to create an ecliose project for the tests folder and run that one
  as an andrdoid instrumentation.
  On Dec 8, 2010 11:51 AM, Etienne Lawlor lawloretie...@gmail.com wrote:
   Yes i am using Eclipse. I did all of your steps up to the point where you
   said

  So, if you used /home/etienne/workspace/MyProject as the location for
  your app project, use the location /home/etienne/workspace/MyProject/
  tests as the location for your test project.

   When i click finish, then i get an error that says:

   'Refreshing workspace has encountered a problem'
   An internal error occurred during: 'Refreshing workspace'
   Element not found: /MyProject/tests.

   It shows a red x icon on the MyProjectTest project but if i clean the
   project
   then this disappears.

   I do see that now there are two projects: MyProject and MyProjectTest.
   In the root directory of MyProject there is a subdirectory /tests.
   In the /tests directory i do see that AndroidManifest.xml file that has
  an
   instrumentation element which seems to be set up properly.

   I don't understand this part of what you said:

  *Even though the tests directory appears in MyProject*, do *not* use
  it to create or run tests. This is a weird artifact of Eclipse; you
  can create a project as a subdirectory of another project, but you'll
  see the second project *inside* the first one.

   So what is the point of the /tests subdirectory if there is a test
  project
   at
   the same level as the app project and you can only run that seperate
  project
   as an Android JUnit test?

   Also when you say:

  If you look in the sample apps, all of them (except one) use the
  best practice that is documented.

   I guess the best practice means that /tests is a subdirectory of
   /MyProject.
   I've seen an example of this in the API Demos. However i don't see how
  you
   can run MyProject as an Android JUnit test, even though there is an
   AndroidManifest.xml with an instrumentation element with a testrunner in
  the
   /tests
   subdirectory.

   Thanks for all your help Joe. This is the first time ive been able to get
   some kind of response
   to my question in this googlegroup.

   On Wed, Dec 8, 2010 at 10:59 AM, A. Elk lancaster.dambust...@gmail.com
  wrote:

   You have not said how you created the test project.

   Reading between the lines, I am guessing that you did it in Eclipse.

   To do it correctly, you should first use the New Android Project
   wizard in Eclipse to create your app project. In the Contents panel,
   in the Location textbox, you can accept the default

[android-developers] Re: testApplicationTestCaseSetUpProperly failing

2010-12-06 Thread A. Elk
It's hard to tell, because you haven't told us very much other than
the error message.

The message itself is what you would expect if you invoked one of the
assert... methods in junit.framework.Assert and the method failed.
This is indicated in the fifth line:

junit.framework.AssertionFailedError

The JUnit Assert class contains methods that throw Exceptions if the
specified assertion is not true. For example,
assertEquals(String,String) will throw an Exception if the two String
objects are not equal.

The assert failed in
android.test.ApplicationTestCase.testApplicationTestCaseSetUpProperly().
This means, in effect, that Android was not able to set up your
application.

You must have created a test project, and it in added a test case
class that extends ApplicationTestCaseT extends
android.app.Application. That test case class will, by default, call
testApplicationTestCaseSetUpProperly().

I can't tell much more than that. Did you create a test project? Did
you define a subclass of ApplicationTestCaseT? Are you sure that T
is the same as the name of your application class?

As a side note, there's usually no reason to run a test on an
Application class. If you want to test an application, you should
run unit tests on its Plain Old Java Objects (POJOs), and Android
functional tests on the application's Android components (Activities,
ContentProviders, etc.).

POJOs can be unit tested in regular JUnit. You're free to use the
Android testing framework, but if your POJO doesn't depend on Android
to run, then you don't *need* the framework.

Android components have to run within the Android framework, so
they're strictly speaking functional tests. You still construct them
with a unit testing philosophy, with one test method for each unique
path through a single Android class. You use the Android testing
framework to run these tests. This is described in the Developer
Guide. The newly-announced 2.3 online Guide contains an expanded
description of testing, under Dev Guide  Framework Topics  Testing.

I suggest that you start by testing one of your Activity classes. The
Dev Guide contains a tutorial on doing this, under Dev Guide 
Tutorials  Activity Testing.

On Dec 1, 12:48 pm, Kurtis Nusbaum klnusb...@gmail.com wrote:
 I'm trying my first hand at running some tests. I'm getting this weird
 error. I'm not sure exactly what's happening. Any ideas about what's going
 on?

 [echo] Running tests ...
      [exec]
      [exec] org.klnusbaum.linkschedule.test.ScheduleTests:
      [exec] Failure in testApplicationTestCaseSetUpProperly:
      [exec] junit.framework.AssertionFailedError
      [exec]     at
 android.test.ApplicationTestCase.setupApplication(ApplicationTestCase.java: 
 102)
      [exec]     at
 android.test.ApplicationTestCase.testApplicationTestCaseSetUpProperly(Appli 
 cationTestCase.java:174)
      [exec]     at java.lang.reflect.Method.invokeNative(Native Method)
      [exec]     at
 android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
      [exec]     at
 android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
      [exec]     at
 android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.ja 
 va:520)
      [exec]     at
 android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java: 
 1447)
      [exec] .
      [exec] Test results for InstrumentationTestRunner=.F.
      [exec] Time: 0.07
      [exec]
      [exec] FAILURES!!!
      [exec] Tests run: 2,  Failures: 1,  Errors: 0
      [exec]
      [exec]

 -Kurtis

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Unit Testing - Activity shutdown

2010-11-30 Thread A. Elk
I'm not sure that the discouragement of exit is in any written
guidelines. I just know that exiting applications is both discouraged
and unnecessary.

I did not say that *finish()* is disallowed. You certainly can use it
to close an Activity that is done with its work. It's not normally
used for the main Activity of an application, because it's assumed
that this Activity is always waiting around for something to do.

I can't say more without knowing more about your code. Your design
seems to be this: You display Terms and Conditions dialog. If the user
does not accept them, you want to go away from the application. I
would design this so that the dialog returns to the Activity that
called it. That Activity would then call finish(). Leave it up to the
user to uninstall the application. You are free to leave the app
installed and present (loaded but not doing anything).

You shouldn't be having a problem with SharedPreferences. In Android
unit tests, it's common for a test method to set up SharedPreferences
with the necessary dependencies before running the actual test. If
possible, you should put this part of the test into setUp(), so that
it's clear that it's part of the fixture. This also isolates the
dependency. In a perfect world, the stuff in SharedPreferences would
be injected as a mock dependency, but in Android this is not easy to
do. Within the scope of a single test method in a test case,
however, SharedPreferences should not change.

I don't rely on SharedPreferences maintaining its state across tests.
In fact, you can run into trouble because of the subtleties of
SharedPreferences. It's not totally clear in the documentation, but a
single instance of SharedPreferences is shared by all of the
instances of an application.

In the Android 2.2 documentation, there's a tutorial on Activity
testing. It's under the Resources Tab, under Tutorials  Activity
Testing. The sample test package for that tutorial demonstrates how to
test saving preferences when an application is completely stopped
using finish() and then re-started.

IOn Nov 30, 12:15 am, Ian ian.fawcett.hun...@gmail.com wrote:
 Got this all working and reliably.

 I still use a state variable to tell me where I am in the state
 machine - not ideal.

 My reliability problems seem to have been down to using
 SharedPreferences to hold state between tests.

 Thanks for the responses.

 Ian Hunter

 On Nov 29, 8:10 pm, Ian ian.fawcett.hun...@gmail.com wrote:







  Thanks for your response - I think this could be enlightening

  However, a few questions...

  On Nov 29, 7:30 pm, A. Elk lancaster.dambust...@gmail.com wrote:

   Can I get clarification here? Does your application call finish() at
   some point? If so, at what point?

   The Android design guidelines strongly discourage the use of an exit
   button. You should see that most apps don't have one. The way to
   exit an application is to switch to another one (including a phone
   call) or go to the Launcher/Home. Whenever you switch, the onPause()
   method for the foreground Activity of your app should be called.
   Whenever you switch back, the onResume() method should be called.

  Can you please point me at the guidelines you are referring to?

  I have seen many references to the finish() method, but nothing
  discouraging its use. In the API it states...

  void finish() - Call this when your activity is done and should be
  closed.

  In my scenario, the user rejects the Terms  Conditions in a dialog -
  and this seems the ideal thing to do, No?

   I acknowledge that sometimes you may want to start a child *Activity*
   and then kill it when you're done with it. To do this, use
   finishActivity() with a result code. You may also want to start a
   service when your app starts, but give the user the option to stop the
   service if it's not being used. That's OK too, but you shouldn't shut
   down the app itself.

   In short, the Android model is that you leave the application paused,
   and let Android destroy it to free up resources. If Android does this,
   it should always call the onPause() method of any Activities that are
   still running.

   Can you describe your test harness in more detail? To unit test an
   Activity, you shouldn't need anything more than
   InstrumentationTestRunner and ActivityInstrumentationTestCase2. This
   is documented under Testing and Instrumentation in the Android 2.2
   Developer's Guide.

  I am using the ActivityInstrumentationTestCase2 as you suggest and
  calling getActivity() to start the Activity. I then do
  button.performClick() which causes 'finish()'. I am hoping to reliably
  test that the Activity has paused, stopped or whatever happens.

  I have refactored and now have a unit test which (via a state
  variable) does work, but not reliably - this may be another story :-)

  Thanks
  Ian Hunter

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send

[android-developers] Re: Unit Testing - Activity shutdown

2010-11-29 Thread A. Elk
Can I get clarification here? Does your application call finish() at
some point? If so, at what point?

The Android design guidelines strongly discourage the use of an exit
button. You should see that most apps don't have one. The way to
exit an application is to switch to another one (including a phone
call) or go to the Launcher/Home. Whenever you switch, the onPause()
method for the foreground Activity of your app should be called.
Whenever you switch back, the onResume() method should be called.

I acknowledge that sometimes you may want to start a child *Activity*
and then kill it when you're done with it. To do this, use
finishActivity() with a result code. You may also want to start a
service when your app starts, but give the user the option to stop the
service if it's not being used. That's OK too, but you shouldn't shut
down the app itself.

In short, the Android model is that you leave the application paused,
and let Android destroy it to free up resources. If Android does this,
it should always call the onPause() method of any Activities that are
still running.

Can you describe your test harness in more detail? To unit test an
Activity, you shouldn't need anything more than
InstrumentationTestRunner and ActivityInstrumentationTestCase2. This
is documented under Testing and Instrumentation in the Android 2.2
Developer's Guide.

On Nov 29, 1:33 am, Ian ian.fawcett.hun...@gmail.com wrote:
 OK. Just run up the same app, press exit button and I get a call to
 onStop(), then onDestroy(). That, I assume is what happens on the
 finish() method. Notice no call to onPause() :-\

 So, it looks like the test harness has a different behaviour.

 A temporary, poor solution has been to create an interval variable
 which gets set on state transitions (onPause(), onCreate() etc.), and
 then query that variable in my test harness. Then I use
 'assertTrue(state != RUNNING)'.

 Not good, but I can move on for now.

 Any better solutions, or insights appreciated.

 Thanks
 Ian Hunter

 On Nov 29, 8:20 am, Ian ian.fawcett.hun...@gmail.com wrote:







  Thanks for the response.

  In my test harness, I do 'button.performClick()', which itself calls
  activity.finish().

  According to docs...

  If an activity is paused or stopped, the system can drop it from
  memory either by asking it to finish (calling its finish() method), or
  simply killing its process.

  So I would expect onDestroy().

  I'm going to trace through (without the test harness) and see what
  actually happens.

  There still remains the question - how do I know onPause() was called?
  Ideally I need a callback, or a way of querying the activity for its
  state.

  Any help appreciated

  Ian Hunter

  On Nov 28, 9:41 pm, Frank Weiss fewe...@gmail.com wrote:

   Chances are what you mean by activity exits is not in line with the
   Android activity lifecycle. Why do you think that the onPause() callback 
   is
   not sufficient in this case?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Android Testing

2010-11-23 Thread A. Elk
Depends on exactly what you mean by while testing. If you are using
the Android unit testing framework described in

http://developer.android.com/guide/topics/testing/testing_android.html

then the answer is no. The unit testing framework is for testing a
single class, so you can't test more than one Activity at a time. If
the Activity under test is dependent on the results of another
Activity, then you have to mock the dependency somehow.

If you want an automated test of the entire application, then you can
use 3rd party test frameworks like Robotium (http://code.google.com/p/
robotium/wiki/Getting_Started).

Somebody mentioned the UI/Application Exerciser Monkey (http://
developer.android.com/guide/developing/tools/monkey.html). This may or
may not fit your circumstances. It was not designed to do functional
testing, though.

On Nov 22, 9:09 pm, kampy narasimha1...@gmail.com wrote:
 hi

 while testing a activity can we move from that activity to the another
 activity . i think it is possible as i found that we can deploy a
 complete test application a android app but i am not gettig how i can
 move from one acitivity to another activity 

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Hello World doesn't work

2010-11-23 Thread A. Elk
To expand on this:

The behavior the OP is seeing is the emulator starting up. During
startup, the text Android will blink. Even on a fast machine, it may
take several minutes for the emulator to load and start the program.
For this reason, you should leave the emulator running if possible
while you're working, or work with an actual device if you can.

If the application does not start after 10 minutes, then something is
wrong.

On Nov 22, 11:13 pm, Kumar Bibek coomar@gmail.com wrote:
 Wait for some time. Let it run. The first run of the emulator always takes
 longer that you would expect. :)

 Kumar Bibekhttp://techdroid.kbeanie.comhttp://www.kbeanie.com







 On Mon, Nov 22, 2010 at 12:23 AM, Naveen naveen.ven...@gmail.com wrote:
  Hey folks,

  Couple of days back, I read some articles about Android and from that
  moment I fell in love with Android development :) I explored
  Developing Android apps for the past few days and done the
  following,

  * Installed the latest Android SDK i.e., 2.2 version. Also updated all
  the installed packages using SDK manager

  * Installed Eclipse IDE for Java EE developers

  * Installed Android plugin for Eclipse

  * Created AVD and selected the target platform as Android SDK 2.2

  * Written a new HelloWorld program with the below code,

  package com.example.helloandroid;

  import android.app.Activity;
  import android.os.Bundle;

  public class HelloAndroid extends Activity {
     /** Called when the activity is first created. */
    �...@override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
     }
  }

  When I try to run the code Hello World is not printed in the
  emulator. Just the text Android blinks in the middle of the device/
  emulator.

  The following is printed in the console when I ran the code

  [2010-11-21 10:51:12 - HelloAndroid] --
  [2010-11-21 10:51:12 - HelloAndroid] Android Launch!
  [2010-11-21 10:51:12 - HelloAndroid] adb is running normally.
  [2010-11-21 10:51:12 - HelloAndroid] Performing
  com.geek.HelloAndroid.HelloAndroid activity launch
  [2010-11-21 10:51:12 - HelloAndroid] Automatic Target Mode: launching
  new emulator with compatible AVD 'HelloAndroid'
  [2010-11-21 10:51:12 - HelloAndroid] Launching a new emulator with
  Virtual Device 'HelloAndroid'
  [2010-11-21 10:51:27 - HelloAndroid] New emulator found: emulator-5554
  [2010-11-21 10:51:27 - HelloAndroid] Waiting for HOME
  ('android.process.acore') to be launched...

  Could you please let me know is there any issue with the code or the
  procedure? It would be really helpful if you point some good basic
  references for developing Android apps..

  TIA.

  Naveen Venkat

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.comandroid-developers%2Bunsubs 
  cr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Android Testing

2010-11-23 Thread A. Elk
I interpret this to mean that you tried to test with the emulator.
Which commands give you permission denied?

On Nov 22, 10:57 pm, kampy narasimha1...@gmail.com wrote:
 hi

 as u said i read the doc and there i found that i can do these testing
 on the emultor terminal adb shell  but for every command i typed it is
 giving the permission denied . how to obtain the permissions for
 this ..

 On Nov 23, 11:22 am, welly tambunan if05...@gmail.com wrote:







  have u try this one

 http://developer.android.com/guide/developing/tools/monkey.html

  http://developer.android.com/guide/developing/tools/monkey.html

  On Tue, Nov 23, 2010 at 12:09 PM, kampy narasimha1...@gmail.com wrote:
   hi

   while testing a activity can we move from that activity to the another
   activity . i think it is possible as i found that we can deploy a
   complete test application a android app but i am not gettig how i can
   move from one acitivity to another activity 

   --
   You received this message because you are subscribed to the Google
   Groups Android Developers group.
   To post to this group, send email to android-developers@googlegroups.com
   To unsubscribe from this group, send email to
   android-developers+unsubscr...@googlegroups.comandroid-developers%2Bunsubs
cr...@googlegroups.com
   For more options, visit this group at
  http://groups.google.com/group/android-developers?hl=en

  --
  Welly Tambunan
  PT. InforSys Indonesia
  RD Department

 http://weltam.wordpress.comhttp://www.triplelands.com/blog/

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Android Project association with an emulator(s)

2010-11-17 Thread A. Elk
This tells me what steps you've taken. Why are you trying to do this?
What you are actually doing is connecting two different devices to
your workstation and then trying to run project A on device1 and
project B on device2. No reason why you can't do this. You should use
the Run Configuration dialog. From the main menu, select Run  Run
Configurations... and put together a run configuration for each
project, complete with the AVD target you want to use.

On Nov 14, 7:45 am, adithya 24adit...@gmail.com wrote:
 Hi,

 I have developed two projects.
 In the first one i send messages and in the second one i receive them.

 I have also created two emulator instances.

 What i was trying to do was associate a single project with a single
 emulator by going to :
 sendProject - run config - selecting the AVD (AVD1)

 For the second project i did the same
 receiveProject - run config - selecting the AVD (AVD2)

 ..then after sending the message when i checked the AVD2 screen it
 threw an error !!

 I went back and checked the run config for both the projects and found
 that both were pointing to the second AVD2 !!

 What could be the reason behind this ?

 Thanks,
 Adithya

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Android ServiceTestCase, two Service instances running?

2010-11-17 Thread A. Elk
The problem here is that your Service is started with instrumentation.
Anything else that starts up is outside the control of the
instrumentation. Though I'm not certain of this, I would expect that
you'd get the behavior you see. The second component that starts up is
not aware of the first Service instance, which is running in a special
part of Android. For this reason, the Service is re-started.

In general, you can't rely on using the unit testing framework to do
functional tests. It's not designed for that, and in most cases it
won't work as you expect it to. The Android test case classes are
there to make JUnit-style unit testing possible within the Android
environment. They're not a substitute for functional/framework-level
testing.

If you want a higher-level testing framework, you may want to look at
monkeyrunner. This tool is available in the Android Open Source
project.

Joe

On Nov 17, 6:55 am, Faboom bu...@uni-koblenz.de wrote:
 Hello,
 i know it should be impossible, but maybe under tests its a different
 thing.
 The test is a functional test, which involves other system components
 such as BroadcastReceiver and Activities. It is SDK 1.6.

 I start the service within a ServiceTestCase without injecting custom
 context or application.

 During the test another android component starts (as intended) the
 same service again with Context.startService(Intent bar).
 Instead of calling onStart in the existing Service, a new Instance of
 the Service is created.
 The logs report via this, that two different service objects are
 running in parallel.

 How can I test the behavior of a service that is started multiple
 times with different intents?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Fetch Spinner value outside setOnItemSelectedListener

2010-11-14 Thread A. Elk
Which tutorial is flawed? As far as I can tell, the Spinner sample app
and the testing tutorial are correct. Perhaps you assumed something
about the Android system that isn't true?

On Nov 12, 7:11 pm, sisko adeod...@gmail.com wrote:
 Tried your suggestion and it's worked.

 Sorry for wasting your time. I'm a newbie following what has turned
 out to be a flawed tutorial.

 Thanks for your patience and help.

 On Nov 12, 3:29 pm, TreKing treking...@gmail.com wrote:







  On Fri, Nov 12, 2010 at 5:05 AM, sisko adeod...@gmail.com wrote:
   So the input is set in a sharedpreference and writing that value back into
   the EditView whenever the activity is restarted.

  Then just do the same thing with the index of the spinner.

  --- 
  --
  TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
  transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Is it a UNIT Test or an Integration test?

2010-11-10 Thread A. Elk
Good catch!

The entire test package contains a *suite* of unit tests against
methods in the application under test.

They are unit tests because they test the smallest testable part of
the application, which is a single method written by the user.

In practice, multiple unit tests are run sequentially in a test suite.
Each test is independent, not relying on the results of a previous
test. The tests are usually grouped together into a test case class so
that each application class has a test case class. All of this is just
practice and subject to individual use.

JUnit (version 3), on which Android test case classes are based,
simplifies this strategy. The special methods setUp() and tearDown()
are run before and after each test to ensure that each unit test is
independent. Any other method beginning with the string test is run
as a unit test.

The only thing that is different is the environment in which an
Android unit test runs. Anything that uses Android has to run within
the Android environment. For that reason, simply calling the
onCreate() method for one of your Activity classes won't work, because
Android has its own lifecycle for objects. That's why the test case
class in the example you cite subclasses
ActivityInstrumentationTestCase2. It is using both JUnit and
InstrumentationTestCase to provide the test case. JUnit allows you to
run the test case class like a JUnit test case, while
InstrumentationTestCase allows you to use Android instrumentation to
control the Activity under test. Even using the virtual machine to run
the class under test wouldn't work correctly.

The Activity context is a dependency. You can have dependencies in a
unit test. It's perfectly OK to run a unit test in a particular
context, as long as you have complete control over the context.
ActivityInstrumentationTestCase2 gives you this control, as do other
mock classes in the Android API.

In short, the differences you see between the example and a standard
test case are because of the Android environment.

I would include unit tests of *everything* in my test suite. It's not
so much a matter of it being a GUI, as much as it being a testable
unit. A test in which you enter text in an edit box, click a button,
and see the result is not necessarily a unit test; I would call it a
functional test. A test in which you start  put text in an edit box,
call the method processEditBox(), and look at the result that the
method returns *is* a unit test. Putting text in the edit box is
setting up a dependency.

It seems to me that the key point in a unit test is to isolate the
behavior you're testing from all other behaviors in the application,
so that you're not unconsciously using external dependencies.

I'm interested in hearing the responses of others in your class, and
your instructor as well.



On Nov 9, 5:47 am, Ians ian_steenbrug...@live.nl wrote:
 I'm working on a school project and I'm researching testing
 possibilities for Android applications.

 On this 
 page:http://developer.android.com/resources/tutorials/testing/helloandroid...
 Google writes about a unit test.

 Is this really a unit test? A Unit test will not integrate all classes
 and will not test in his context. So my opinion is it is not a Unit
 Test but an Integration Test.

 What do you think?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Fetch Spinner value outside setOnItemSelectedListener

2010-11-08 Thread A. Elk
In the Android 2.2 SDK there's a sample app (new for 2.2) called
Spinner that demonstrates how to do this using SharedPreferences. It
will save the state of the spinner across pause() and resume(), and
also across app shutdown and restart.

Even better, it comes with a test package project called SpinnerTest
that demonstrates the unit test for this.

And best of all, the Activity Testing tutorial uses this app and its
test package to demonstrate unit testing in Android.

Enjoy!

The Elk

On Nov 7, 3:09 pm, sisko adeod...@gmail.com wrote:
 Hi guys,

 I have a spinner successfully working but I am trying to use the
 spinner.setSelection method to remember the previous spinner value
 when the activity is reloaded.

 Outside of setOnItemSelectedListener, is there a function of the
 spinner that can give me the selected index?

 The following code is my function code to both setup the spinner and
 then my attempt to set the spinner with the index previously selected:

 private void setSpinner(int spinnerID){
                 final Spinner spinner   =
 (Spinner)findViewById(R.id.Spinner_gender);
                 int spinner_value;

                 spinner.setOnItemSelectedListener(
                                 new AdapterView.OnItemSelectedListener() {
                                         public void 
 onItemSelected(AdapterView? parent, View
 itemSelected, int selectedItemPosition, long selected){
                                                 spinner_value   =       
 selectedItemPosition;
                                                 Editor editor   =       
 mGameSettings.edit();
                                                 
 editor.putLong(GAME_PREFERENCES_GENDER,
 selectedItemPosition);
                                                 editor.commit();
                                                 
 Toast.makeText(QuizSettingsActivity.this, selected:
 +GAME_PREFERENCES_GENDER+(+ spinner_value +),
 Toast.LENGTH_SHORT).show();
                                         }

                                                 @Override
                                                 public void 
 onNothingSelected(AdapterView? arg0) {
                                                         // TODO 
 Auto-generated method stub

                                                 }

                                         }
                 );

                 ArrayAdapter? adapter   =       
 ArrayAdapter.createFromResource(this,
 spinnerID, android.R.layout.simple_spinner_item);

 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_it 
 em);
                 spinner.setAdapter(adapter);
                 if( mGameSettings.contains(GAME_PREFERENCES_GENDER) ){
                         spinner.setSelection(spinner_value);
                 }

         }

 All I am trying to do here is use spinner_value to remember the
 selected index so I can set the spinner to that index.
 However, the spinner_value is never holding the desired value at
 spinner.setSelection(spinner_value); in the last lines of code

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Android JUnit Testing of Paste

2010-11-05 Thread A. Elk
Can you clarify? You want to simulate a long press in an edit box,
followed by a selection of the paste menu item?

If so, get hold of the Android 2.2 SDK documentation. In it, under the
Resources tab, there's a tutorial on unit testing an Activity:

http://developer.android.com/resources/tutorials/testing/activity_test.html

This uses the test case class ActivityInstrumentationTestCase2, which
inherits from InstrumentationTestCase.

Part of the tutorial shows how to get focus on a UI widget. In your
case, you'd get focus on the edit box.

From there, you need to bring up the context menu. I think you could
use TouchUtils.longClickView() to do that. That puts focus on the
menu, I think. From there, send DPAD_DOWN key events to move the
highlight to the paste option, then DPAD_ENTER to select it.

Keep in mind that I've never tried to do this on a menu. I just
provide this as a guideline for trying to solve the problem.

Also keep in mind that Android JUnit testing is really focused on
*unit* testing. If you're really trying to test functionality, there
are better options. IMHO, the difference is that unit testing goes
method-by-method, with the assumption that all methods and classes are
independent. You inject all external dependencies, either with mocks
or actual objects. Functional testing goes from the beginning of a
user task to the end. For example, a functional test of a calculator
app would enter a 2, enter a +, enter another 2, enter an =, and check
to see that 4 is displayed.



On Nov 4, 12:41 pm, Zymurgeek zymurg...@gmail.com wrote:
 How do I go about simulating a context menu paste command using the
 Android JUnit tests?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: What are some good Automated Unit And System Test Tools for Android?

2010-11-03 Thread A. Elk
The open source SDK now has a tool called monkeyrunner, with an API
for starting instrumentation from within a Python script. The call (in
essence) returns a string containing the test results, as if you had
intercepted the output from am instrument. One of the API methods
prints out some help, and a little birdie has told me that more docs
will be made available.

Elk

On Nov 2, 11:20 pm, Greg Giacovelli miyamo...@gmail.com wro
 So I give in. I approached this problem as an oh hey that's not too
 bad, I can write a bunch of unit tests, and I have been keeping my
 suite green. However as things get more involved continuous
 integration and testing is a great great thing to have. And then I saw
 oh Android has emma integration as well awesome ... and then that's
 where it get's iffy.

 So I setup Hudson and have it call the coverage target of the ant
 build.xml that the android executable in the sdk can generate. And
 then it hits me.

 adb -s emulator shell am instrument -w ...

 will never return a result code that is not 0 ... because adb
 technically exited cleanly and usually will regardless of how the
 shell command that executed did.

 So again I say, Oh that's not too bad, I can just wrap adb with a
 parser that parses output for errors and return a non 0 resultcode to
 fail my build if a test fails. Problem is then I also want to see what
 tests fail. I know eclipse is doing something smarter so I dig deeper
 and find the extra switches you can pass am instrument including the -
 r flag.

 adb -s emulator shell am instrument -r -w ...

 Now this is starting to get complicated as the output gets more
 complex and this originally thought simple task is getting more
 intense. As this SDK is maturing more I have to think, someone has
 endured this pain and made a kickass way to automate and report on
 these sdk tools and output. Like something complete with performance
 test tracking, code coverage reporting etc. These outputs all exit in
 the SDK but they just have to be adapted to the tools used outside. I
 have to think after a year or two this adapter(s) has to have been
 written. However I have only been able to find blackbox testing
 frameworks and not anything along the lines of regression test suite
 automation of the whitebox sort.

 Any suggestions welcome.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Problem in running test case

2010-10-21 Thread A. Elk
This class looks OK to me, with one possible exception that I'll
mention at the end.

You didn't post the manifest file for this test package. The problem
might be there.

You said when I extend this class with InstrumentationTestCase...
Can you post exactly what you mean? Which class is this class? You
should not have to extend TestCaseOne with *both*
ActivityInstrumentationTestCase2 *and* InstrumentationTestCase, since
ActivityInstrumentationTestCase2 itself extends
InstrumentationTestCase. So please clarify what you mean.

One off-the-wall thought: Your first test is named test001case(). I
know that JUnit 3 figures out which methods in a test case are tests
by looking for a prefix of test. If it strips off the test, the
method name that remains is 001case, and I wonder if that causes
hiccups somewhere. I try to name all my test methods with a
description of the method or operation they're testing. As an example,
to test an Activity's onPause() method I'd name the test
testOnPause(). Try using a non-numeric name and see what happens.

Joe

On Oct 20, 2:23 am, Siddharth Choudhary elegants...@gmail.com wrote:
 Hello ,

 I am working on android automation ,and i am new to this field , i
 went through the test example available at developer site and i am
 getting

 11-05 14:43:14.509: WARN/TestGrouping(1485): Invalid Package: '' could
 not be found or has no tests

 as  error on running  this code .

 package com.android.myservice.test;

 import com.android.myservice.MockActivity;

 import android.test.ActivityInstrumentationTestCase2;
 import android.util.Log;

 public class TestCaseOne extends
 ActivityInstrumentationTestCase2MockActivity {

         public TestCaseOne(String pkg, ClassMockActivity activityClass) {
                 super(com.android.myservice.test, MockActivity.class);
         }

         public void test001case()
         {
                 Log.e(, test case 001);
         }

 }

 But when i extend this class with InstrumentationTestCase then this
 code work's fine please let me know what mistake am i  doing in using
 ActivityInstrumenationTestCase2.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: using instrumentation testing framework if there is more than one activity

2010-10-18 Thread A. Elk
The instrumentation testing framework is designed to do unit tests.
It's not a replacement for a full testing framework; instead, it
allows you to do true JUnit-style unit testing on Android component
classes.

Robotium is more of a functional/application-level testing framework.
Within object-oriented programming (strictly speaking), a unit test
tests an individual method by calling it in a controlled environment
and evaluating its results. The structure of test cases that Robotium
uses is similar to that of JUnit, but Robotium's level of work is a
class (an Activity, for example), not a method. In that sense, it's a
test harness for functional testing of a class.

Automated functional testing is necessary, but so is unit testing. The
latter is particularly important when you are modifying existing
behavior. IMHO, unit testing is also better at identifying
dependencies.

Android itself has monkey, which is *a* tool for doing functional
testing, but has limited applicability.

On Oct 18, 12:18 am, Mathias Lin m...@mathiaslin.com wrote:
 Hi Andrei, not directly answering your question, but just want to
 point you towww.robotium.org, which is a testing framework and does
 tests across multiple activities.

 On Oct 18, 11:02 am, Andrei gml...@gmail.com wrote:



  How do I use instrumentation testing framework to test flow between
  activities?
  The example goog gives is for one activity only
  Thanks

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: unit testing asynchronous API calls ?

2010-10-04 Thread A. Elk
I would like to point out that, as far as I can tell, you're not doing
a real unit test.

It seems that you have at least two components. So let's say you have
two, component A and component B. You would like to test both, but you
first have to call A, which calls an asynchronous process that does
something and then triggers B. Is this correct? If so, the whole
sequence is not a unit test. A true unit test would be to call A and
then verify its results. To do that, you might have to have a test
version of the asynchronous process. To test B, you'd have to set up a
fixture that mocks the results of the asynchronous process, then you'd
have to call B.

The classes in android.test.* are not a substitute for a full test
harness. Instead, they're extensions of junit.framework.TestCase that
allow you to run JUnit within Android. To do testing of more than one
component at a time, you have to write your own test harness, and
notice that it has to be an Android app.

On Oct 3, 2:28 pm, Doug beafd...@gmail.com wrote:
 On Oct 2, 9:28 pm, Alex aleksm...@gmail.com wrote:

  I was wondering what is the best  way to accomplish this ?

 I can suggest a solution, though it may not be the best.

 You probably going to have to set up some kind of listener interface
 to be implemented in your unit test that triggers after the result is
 processed by the UI thread.  Otherwise, you'll have to figure out
 another way to detect when the processing is complete.

 In you make a listener the responds to completion, you'll have to then
 signal junit that it completed so it can assert what it needs to
 assert.

 An easy way to do that is:
 - Define a CountDownLatch that you create before executing AsyncTask
 - After executing, call await on the latch (with a timeout if you need
 it)
 - In the callback listener, call countDown on the latch to notify the
 test that it's done

 Basically, you just need to make the junit thread to wait for the
 results, and you can use any standard multithreading technique to do
 it.

 But if all you need to do is validate the results of a task without
 needing to run it on the UI thread, you could just try to call the
 methods on the AsyncTask directly (don't use execute()) and detect the
 results when the methods complete normally.

 Doug

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How to check that activity displays dialog during unit testing

2010-09-27 Thread A. Elk
It's difficult to check for a dialog using unit tests. Keep in mind
that unit tests are supposed to test individual methods, and what
you're trying to do is at a somewhat higher level. A unit test would
test the results of clicking mLoginButton, and you don't include this
part of the code.

I am curious: is there a particular reason that you're calling
instr.addMonitor? Are you testing another Activity besides
MainActivity when you call this?

A. Elk.

On Sep 23, 11:24 pm, Eugeny kropotin ekropo...@gmail.com wrote:
 Hello, Android Developers! I have some question for you.

 I want to write testcases for my android application using JUnit. And
 I faced some problems.

 Is it possible to check that activity displays some dialog at current
 moment? Here is a small piece of my test application:

     ...
     Instrumentation instr = getInstrumentation();
     monitor = instr.addMonitor(MainActivity.class.getName(), null,
 false);
     /* Click on login button */
     TouchUtils.clickView(this, mLoginButton);
     /* wait MainActivity */
     mMainActivity = instr.waitForMonitorWithTimeout(monitor, 3);
     assertNotNull(mMainActivity);
     /* Here a want to check that progress dialog displayed on
 mMainActivity */

 Thanks in advance!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Newbiew question: authoroties

2010-09-27 Thread A. Elk
The application that offers the provider needs to have the provider
element in its manifest file. This declares the provider to Android.
Any other application that uses the provider has to know the
provider's authority.

So if application A creates the provider, then application A's
manifest must include something like:

provider android:name=com.somename.ProviderClass
  android:authorities=com.somename.theprovider/
/provider

com.somename.ProviderClass is the fully-qualified name of the class
that extends ContentProvider. The android:authorities attribute
provides a unique name for the provider. The best way to get a unique
name is to use a domain name you own. For example, the OP could make
an authority
com.pedroteixeira.org.somename.theprovider as the authority. See
http://developer.android.com/guide/topics/providers/content-providers.html
for more details.

If you're sure that you don't have the providers element in both
applications, then it's possible you've mistakenly copied an authority
from an example somewhere, and that authority is already installed on
your device. Android maintains a global table of providers, organized
by authority name.


On Sep 27, 8:10 am, Pedro Teixeira pedroteixeir...@gmail.com wrote:
 Anyone has a clue about this?

 Please... I have to applications... one has a provider tag in the  
 manifest, the other doesn't have anything.
 And I keep getting this error but I don't know how can I change it  
 since I don't know which one is the standard.

 On Sep 27, 2010, at 8:59 AM, Pedro Teixeira wrote:





  Hi all,

  I know this will be elementray but I'm not finding anywhere for a
  straightforward answer...
  I'm getting this : Installation error:
  INSTALL_FAILED_CONFLICTING_PROVIDER

  Which apparentlly seems I'm I give the provider an authority which is
  already being used by another app on the system.

  I mean.. how do I change that? What authority are everyone talking
  about, I can't find anything like that in the manifest...

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

 Pedro Teixeira

 www.pedroteixeira.org

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Documentation tutorials

2010-09-14 Thread A. Elk
It's not a valid excuse that Android is open source. I assume that
Google wants to make Android extremely successful, at least as much as
other free/open source products it offers. Look at Google Maps; it
has an open API as well.

Writing, maintaining, and updating documentation may be boring and
tedious for engineers, but I have to assume that it isn't for
technical writers who are paid to do it. I assume that Google has
technical writers working on the Android SDK documentation, unless
they have a bunch of engineers who are doing nothing but
documentation.

I have to hope that Google won't be offended by complaints about
documentation, and that instead they'll want to improve it. Having
said that, it's like software; the best feedback provides specific
examples where the documentation is not sufficing. Of course, maybe
you can't provide anything more than I am confused, and the
documentation isn't helping or It takes too long, and the
documentation isn't helping.

I haven't developed for iOS, but if developers think that iOS apps are
easier to develop and that the documentation is part of this, then
maybe Google will listen to that criticism and take a look at the iOS
documentation.

A. Elk (the brontosaurus is thinner at one end...)

On Sep 14, 10:40 am, TreKing treking...@gmail.com wrote:
 On Tue, Sep 14, 2010 at 12:31 PM, DanH danhi...@ieee.org wrote:
  I'm not sure why there's such a dearth of good Android documentation

 Probably because writing, maintaining, and updating documentation is a
 boring, tedious job.

  especially given that what I'd like most is a good basic reference (which
  would normally be the first thing written), vs some sort of hand-holding
  tutorial.

 Isn't that what the official documentation is?

 --- 
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
 transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: UriMatcher match not working properly

2010-09-09 Thread A. Elk
As far as I can tell from what you've posted, you're declaring
CONTENT_URI as a String or some sort of string-related immutable
class. If you look at the NotePad example, CONTENT_URI is of type Uri,
and it's constructed using Uri.parse.

You may be doing this, but what you've posted doesn't indicate it.
Always be sure to post the exact code you're using.

My first suggestion is to double-check that you have constructed the
content URI correctly in the code, using Uri.parse.

Next, do some debugging. I assume that what you *think* you're passing
to your content provider is not what is actually getting to it. I also
assume that you're already doing some debugging, since you know that
uri.Match is returning -1.



On Sep 8, 10:21 pm, Arpit robin.ca...@gmail.com wrote:
 Somehow my UriMatcher is not working properly and because of that I am
 not able to do the CRUD operations on my tables.

 I have the following structure of packages and classes:

 com.arpit.provider : This has a class MyContentProvider which extends
 ContentProvider class
 com.arpit.tables :
         DatabaseHelper extends SQLiteOpenHelper
         KeyTable implements BaseColumns
         ParticipantTable implements BaseColumns

 Now in MyContentProvider, I have done the following:

 ...
 public static final String AUTHORITY =
 com.arpit.provider.MyContentProvider;
 ...
 static{
         UriMatcher uriM = new UriMatcher(UriMatcher.NO_MATCH);
         uriM.addUri(AUTHORITY, key, 0);
         uriM.addUri(AUTHORITY, participant, 1);}

 ...
 public Cursor query(Uri uri, String[] projection, String selection,
                         String[] selectionArgs, String sortOrder) {
                 SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
                 switch(uriM.match(uri)){
                         case 0:
                                 qb.setTables(key);
                                 break;
                         case 1:
                                 qb.setTables(participant);
                                 break;
                 }
 }

 ...

 In my KeyTable class, CONTENT_URI = content:// +
 MyContentProvider.AUTHORITY + /key;
 In my ParticipantTable class CONTENT_URI = content:// +
 MyContentProvider.AUTHORITY + /participant;

 In my AndroidManifest.xml file I have registered the provider as:

 provider android:name=com.arpit.providers.MyContentProvider
         android:authorities=com.arpit.providers.MyContentProvider/
 provider

 Now I make the query call with the following statement in my
 HomeActivity:

 Cursor cursor = getContentResolver().query(KeyTable.CONTENT_URI, new
 String[] { KeyTable.col1 }, _id='1', null,  null);

 My problem is when the Query Method is called and the Switch block is
 executed the uriM.match returns always -1 (irrespective of whether it
 is KeyTable.CONTENT_URI or ParticipantTable.CONTENT_URI).

 Could you let me know what wrong am I doing because of which it is not
 working.

 From the note pad example I see during debug the only difference is
 they call managedQuery instead of getContentReslover().query(...). I
 tried firing managedQuery(...) in my HomeActivity class, but that also
 result in uriM.match(uri) to return -1.

 It will be great if you could help me out.

 Thanks  Regards,
 Arpit

 On Aug 25, 10:20 pm, A. Elk lancaster.dambust...@gmail.com wrote:



  The Note Pad example is pretty good for URI content matching.

  Basically, you define one or more URIs for a ContentProvider. Don't
  think of them as URLs, just think of them as strings with a
  particular format. Using web domains in them is a easy, nearly
  foolproof way to ensure that each URI is unique. For example, I can
  safely use the content URI content://database.lancaster.dambusters.gmail.com
  because that's my unique GMail address.

  Patterns come in when you want a ContentProvider to return different
  things depending on the exact URI. In the Note Pad sample (*not* the
  tutorial), there are 3 patterns corresponding to 3 forms of data: a
  list of notes, a single note, or a set of notes compatible with the
  LiveFolder widget. The list of notes form is set up in the code and
  the manifest so that it returns a set of records. The single note
  returns exactly one note, and I forget offhand what LiveFolders does.
  Let's look at the first two.

  For set of notes, you just specify a base URI. The Provider returns
  all the notes in the database that match your criteria.

  For a single note, you specify a pattern that is the single note
  base URI with a note ID number appended to it. The ID number is the
  value of the _ID column for the record you want. The Provider
  returns that particular note. As written, the Provider can also filter
  the note by selection criteria.

  If you look in the code for the Provider, you'll see that it defines 
  aUriMatcher. You useUriMatcher.addUri() to match an authority (a
  base URI without a specific pattern) and a pattern to a value. When a
  URI comes in to the query

[android-developers] Re: UriMatcher match not working properly

2010-09-09 Thread A. Elk
I missed the mismatch as well; it's subtle. In your manifest, you set
the authority to com.arpit.providers.MyContentProvider, while in the
code you set it to com.arpit.provider.MyContentProvider. Note the
missing s for provider in the code. The ContentResolver shouldn't be
able to resolve your provider, so you should always get back null when
you call it. This rouses my curiosity; how do you know that UriMatcher
is always returning -1?

On the whole, it would be better in this case to do some debugging
first. If you provide values to a function, but it doesn't act as you
expect, then either you passed in the wrong values or misunderstood
the requirements. Check the values for correctness before you assume
you misunderstood something.

Content provider users should also consider writing unit tests for
their providers. ProviderTestCase2 is a good, comprehensive way to
test a provider in isolation.

elk.

On Sep 9, 11:15 am, Brion Emde brione2...@gmail.com wrote:
 You should not hijack existing threads with new questions that do not
 correspond to the original thread. That makes it very difficult for
 people to find the original thread. Instead, you should start a new
 thread with your question.

 That said, I see that the value of the AUTHORITY that you declare in
 your ContentProvider do not match with the android:authority that you
 declare in your AndroidManifest.xml. You should check that they match.

 Finally, rather than giving snippets of code that you think might be
 useful, it is actually more useful if you give a full example.

 On Sep 9, 1:21 am, Arpit robin.ca...@gmail.com wrote:



  Somehow my UriMatcher is not working properly and because of that I am
  not able to do the CRUD operations on my tables.

  I have the following structure of packages and classes:

  com.arpit.provider : This has a class MyContentProvider which extends
  ContentProvider class
  com.arpit.tables :
          DatabaseHelper extends SQLiteOpenHelper
          KeyTable implements BaseColumns
          ParticipantTable implements BaseColumns

  Now in MyContentProvider, I have done the following:

  ...
  public static final String AUTHORITY =
  com.arpit.provider.MyContentProvider;
  ...
  static{
          UriMatcher uriM = new UriMatcher(UriMatcher.NO_MATCH);
          uriM.addUri(AUTHORITY, key, 0);
          uriM.addUri(AUTHORITY, participant, 1);}

  ...
  public Cursor query(Uri uri, String[] projection, String selection,
                          String[] selectionArgs, String sortOrder) {
                  SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
                  switch(uriM.match(uri)){
                          case 0:
                                  qb.setTables(key);
                                  break;
                          case 1:
                                  qb.setTables(participant);
                                  break;
                  }
  }

  ...

  In my KeyTable class, CONTENT_URI = content:// +
  MyContentProvider.AUTHORITY + /key;
  In my ParticipantTable class CONTENT_URI = content:// +
  MyContentProvider.AUTHORITY + /participant;

  In my AndroidManifest.xml file I have registered the provider as:

  provider android:name=com.arpit.providers.MyContentProvider
          android:authorities=com.arpit.providers.MyContentProvider/
  provider

  Now I make the query call with the following statement in my
  HomeActivity:

  Cursor cursor = getContentResolver().query(KeyTable.CONTENT_URI, new
  String[] { KeyTable.col1 }, _id='1', null,  null);

  My problem is when the Query Method is called and the Switch block is
  executed the uriM.match returns always -1 (irrespective of whether it
  is KeyTable.CONTENT_URI or ParticipantTable.CONTENT_URI).

  Could you let me know what wrong am I doing because of which it is not
  working.

  From the note pad example I see during debug the only difference is
  they call managedQuery instead of getContentReslover().query(...). I
  tried firing managedQuery(...) in my HomeActivity class, but that also
  result in uriM.match(uri) to return -1.

  It will be great if you could help me out.

  Thanks  Regards,
  Arpit

  On Aug 25, 10:20 pm, A. Elk lancaster.dambust...@gmail.com wrote:

   The Note Pad example is pretty good for URI content matching.

   Basically, you define one or more URIs for a ContentProvider. Don't
   think of them as URLs, just think of them as strings with a
   particular format. Using web domains in them is a easy, nearly
   foolproof way to ensure that each URI is unique. For example, I can
   safely use the content URI 
   content://database.lancaster.dambusters.gmail.com
   because that's my unique GMail address.

   Patterns come in when you want a ContentProvider to return different
   things depending on the exact URI. In the Note Pad sample (*not* the
   tutorial), there are 3 patterns corresponding to 3 forms of data: a
   list of notes, a single note, or a set of notes compatible

[android-developers] Re: Eclipse ADT not installing library project

2010-09-08 Thread A. Elk
The uses-library element is documented at
http://developer.android.com/guide/topics/manifest/uses-library-element.html.

The documentation doesn't say this explicitly, but this element is
only for libraries supplied with Android. The default settings exclude
a few libraries from the build's classpath. My guess is that this is
done to save space. I know that you need uses-library for a test
package, because InstrumentationTestRunner is in android.test.runner,
which isn't on the classpath by default.

On Sep 8, 3:29 pm, Ian Pilcher arequip...@gmail.com wrote:
 On Sep 7, 8:08 pm, Xavier Ducrohet x...@android.com wrote:

  In fact, this is why your install fails. The system will look for a
  *system* library named after your compile-time library. Of course it
  will fail finding it and will refuse to install your application.

 I'm not sure where I found the stuff about adding uses-library
 to AndroidManifest.xml.  It's definitely not where I thought it
 was.  I think the reason that my library project didn't work in
 the first place is that I was trying to use it to share an AIDL
 file between client and server projects.  I've since read
 that this doesn't work.

 This does raise the question, what is the best way to
 ensure that the two projects are using the same AIDL file?
 Are people just cutting and pasting?

 Thanks!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: ServiceTestCase does not trigger Service.onStartCommand()

2010-09-03 Thread A. Elk
My guess is that this is a bug. The Android 2.2 SDK says that
onStart() was deprecated in favor of onStartCommand(). The test case
class may not have been updated. Try SDK 2.2?

On Sep 2, 4:07 pm, doug doug_a...@yahoo.com wrote:
 A correction.  It is not Servcie.onStart() but
 Service.onCreate().  My ServiceTestCase derived test case calls
 startService() which does not trigger Service.onStartCommand() but
 only Service.onCreate().  Both Service methods will be called when the
 service starts normally from the application.

 doug

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Testing several projects with a single test project

2010-08-30 Thread A. Elk
The Android instrumentation-based testing framework focuses on unit
testing and component-level functional testing. It's not meant to be a
full multi-application test system. You can't test an activity and the
content provider it uses in the same test case, nor can you test what
happens when the user goes out of one application to change a global
setting and then returns to the same application.

To get around these limitations, you have to write your own test
system.

A.

For example, it's not possible to test two different components (or
their interaction in a single

On Aug 30, 12:19 am, Andrey Panasyuk a.panas...@softteco.com wrote:
   Thank you for the comment.

 Unfortunately it's not the case since we also want to test interaction
 of several applications at a time.

 Now we're looking at a possibility to interact between applications and
 testcases project via services and service connections.



  You can make one test package that is capable of testing several
  applications, but it can only test one app at a time. For each new app
  you want to test, you have to update AndroidManifest.xml to point to
  the new target app, re-build the test package, and re-install it.

  What is your use case? Do you have a set of unit tests that you want
  to apply to different apps? This is a bit unusual, but conceivable.
  You could do this in a shell script. First install all your apps using
  adb install, then use sed or awk to modify the
  AndroidManifest.xml in the test project, build the test package, use
  adb -r to install it, and then adb shell am instrument to run the
  test and see the results. The last command is documented in the
  Android 2.2 Developer's Guide, under Guide  Developing  Testing
  Testing in Other IDEs.

  The Elk.

  On Aug 24, 12:36 am, Andrey Panasyuka.panas...@softteco.com  wrote:
  Hello,

  Is it possible to test several Android projects by having only one
  test project?
  I've tried various ways like specifying several instrumentation tags:

       instrumentation android:targetPackage=com.test1.test11
  android:name=android.test.InstrumentationTestRunner /
       instrumentation android:targetPackage=com.test1.test12
  android:name=android.test.InstrumentationTestRunner /

  or played with the packages but finally I got only tests for one
  application working correctly, tests for the other applications are
  giving java.lang.VerifyError.

  All of the applications are signed with the same key.

  Does anyone know if it is possible?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Testing several projects with a single test project

2010-08-25 Thread A. Elk
You can make one test package that is capable of testing several
applications, but it can only test one app at a time. For each new app
you want to test, you have to update AndroidManifest.xml to point to
the new target app, re-build the test package, and re-install it.

What is your use case? Do you have a set of unit tests that you want
to apply to different apps? This is a bit unusual, but conceivable.
You could do this in a shell script. First install all your apps using
adb install, then use sed or awk to modify the
AndroidManifest.xml in the test project, build the test package, use
adb -r to install it, and then adb shell am instrument to run the
test and see the results. The last command is documented in the
Android 2.2 Developer's Guide, under Guide  Developing  Testing 
Testing in Other IDEs.

The Elk.

On Aug 24, 12:36 am, Andrey Panasyuk a.panas...@softteco.com wrote:
 Hello,

 Is it possible to test several Android projects by having only one
 test project?
 I've tried various ways like specifying several instrumentation tags:

     instrumentation android:targetPackage=com.test1.test11
 android:name=android.test.InstrumentationTestRunner /
     instrumentation android:targetPackage=com.test1.test12
 android:name=android.test.InstrumentationTestRunner /

 or played with the packages but finally I got only tests for one
 application working correctly, tests for the other applications are
 giving java.lang.VerifyError.

 All of the applications are signed with the same key.

 Does anyone know if it is possible?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: About ContentProvider designing in my App

2010-08-25 Thread A. Elk
The Note Pad example is pretty good for URI content matching.

Basically, you define one or more URIs for a ContentProvider. Don't
think of them as URLs, just think of them as strings with a
particular format. Using web domains in them is a easy, nearly
foolproof way to ensure that each URI is unique. For example, I can
safely use the content URI content://database.lancaster.dambusters.gmail.com
because that's my unique GMail address.

Patterns come in when you want a ContentProvider to return different
things depending on the exact URI. In the Note Pad sample (*not* the
tutorial), there are 3 patterns corresponding to 3 forms of data: a
list of notes, a single note, or a set of notes compatible with the
LiveFolder widget. The list of notes form is set up in the code and
the manifest so that it returns a set of records. The single note
returns exactly one note, and I forget offhand what LiveFolders does.
Let's look at the first two.

For set of notes, you just specify a base URI. The Provider returns
all the notes in the database that match your criteria.

For a single note, you specify a pattern that is the single note
base URI with a note ID number appended to it. The ID number is the
value of the _ID column for the record you want. The Provider
returns that particular note. As written, the Provider can also filter
the note by selection criteria.

If you look in the code for the Provider, you'll see that it defines a
UriMatcher. You use UriMatcher.addUri() to match an authority (a
base URI without a specific pattern) and a pattern to a value. When a
URI comes in to the query() method, you use UriMatcher.match to match
the incoming URI to a pattern. The method returns the value that you
associated with the pattern in addUri(). The UriMatcher is defined in
a static block at the end of the code.

As a note, you can use ? in a pattern as a wildcard to match any
string, and # to match any number. The # is used to match a single
note in Note Pad.

The Note Pad code is hard to understand because it's designed to
accept alternate actions. This allows other apps to access the
ContentProvider by specifying the proper authority and MimeType. You
can ignore this, basically. The mime type tells the calling app what
it's gonna get back from the Provider. If the type is
vnd.android.cursor.dir, then the calling app knows it may get back
more than one row, whereas if it gets back cursor.item, it gets back
only one item. Incoming Intents have to specify a mimeType so that
they exactly match Note Pad's intent filters. For example, an app that
sends an Intent with action.GET_CONTENT but mime type
vnd.android.cursor.dir won't match any of Note Pad's intent filters.

The elkmeister.


On Aug 25, 4:04 am, Arpit robin.ca...@gmail.com wrote:
 Thank you all for answering and guiding me with the design. I wanted
 to know whether multiple tables can be part of a content provider. I
 have one database and my requirement is to share the DB across
 application and hence the Content Provider.

 And after normalizing my tables, I realize a single content provider
 will be sufficient to handle all the tables in my db. Though I am
 struggling a little with URI matching concept, so trying some code
 like NoteList example. Once I run my own code, may be i will
 understand better.

 Thanks for the info, it help me a lot with the design.

 Regards,
 Arpit

 On Aug 24, 10:51 pm, A. Elk lancaster.dambust...@gmail.com wrote:



  There are two considerations: database design and application design.

  Database design is much too big of a topic to summarize in a single
  thread! But in short, one wants to normalize the data and do joins to
  combine data from different tables.

  Application design in Android suggests that a ContentProvider isn't
  necessary for private data. Basically, if you don't want to let other
  applications look at your data (or modify it, or delete it) by
  themselves, then you don't really need a ContentProvider. Of course,
  you can have one if you want. You lose a bit of security, since the
  data becomes public, although you can keep pretty much private by
  using an obscure URI.

  Also, it's best to have one database per ContentProvider. If you find
  yourself trying to associate more than one database with the same
  ContentProvider, your design may be suspect. Remember that a single
  database can contain address data, book data, and people data, if the
  domain is library management. On the other hand, you may choose to use
  the built-in Contacts provider for people/address and your own
  ContentProvider for books.

  In short, there's no one answer, except that you aren't limited to one
  table per ContentProvider, one database per ContentProvider, or one
  ContentProvider per Android application. A ContentProvider has some
  overhead, but I'd opt for one per database rather than worry about the
  overhead.

  On Aug 24, 9:17 am, Kostya Vasilyev kmans...@gmail.com wrote:

     A ContentProvider is queried

[android-developers] Re: About ContentProvider designing in my App

2010-08-24 Thread A. Elk
You can associate more than one table with a ContentProvider. You can
even associate more than one database with a single ContentProvider
instance, but considering the amount of extra programming work you'd
encounter, it's best not to.

I'm not sure why you'd want to associate more than one database with a
single ContentProvider. Are you trying to save memory by not having
multiple instances of a ContentProvider? I think that would be a waste
of time and effort, without much gain.

Remember, too, that you don't need to use a ContentProvider in order
to access an SQLite database. ContentProvider is primarily designed to
provide a unified _cross-application_ data source. If you have a local
SQLite database or databases that you don't want to share outside your
application, you can use the android.sqlite.* classes directly.

The examples always use one table because that's the most simple
example.

On Aug 24, 9:01 am, Arpit robin.ca...@gmail.com wrote:
 Hi All,

 All the example codes, tutorials or video I see, there is always one
 ContentProvider per SQL Table with the SQLiteOpenHelper extension
 defined as a private static class...

 Is it some sort of standard design...to have one ContentProvider per
 SQL Table? Or I can define one generic ContentProvider and use its
 instance for ever update?

 Is there some issue with that?

 Could anyone please help as my application has like 5-6 tables.

 Regards,
 Arpit

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: About ContentProvider designing in my App

2010-08-24 Thread A. Elk
There are two considerations: database design and application design.

Database design is much too big of a topic to summarize in a single
thread! But in short, one wants to normalize the data and do joins to
combine data from different tables.

Application design in Android suggests that a ContentProvider isn't
necessary for private data. Basically, if you don't want to let other
applications look at your data (or modify it, or delete it) by
themselves, then you don't really need a ContentProvider. Of course,
you can have one if you want. You lose a bit of security, since the
data becomes public, although you can keep pretty much private by
using an obscure URI.

Also, it's best to have one database per ContentProvider. If you find
yourself trying to associate more than one database with the same
ContentProvider, your design may be suspect. Remember that a single
database can contain address data, book data, and people data, if the
domain is library management. On the other hand, you may choose to use
the built-in Contacts provider for people/address and your own
ContentProvider for books.

In short, there's no one answer, except that you aren't limited to one
table per ContentProvider, one database per ContentProvider, or one
ContentProvider per Android application. A ContentProvider has some
overhead, but I'd opt for one per database rather than worry about the
overhead.

On Aug 24, 9:17 am, Kostya Vasilyev kmans...@gmail.com wrote:
   A ContentProvider is queried (and updated) using a URI, which
 specifies the kind of data to work with. This might look like this:

 content://provider/counties
 content://provider/counties/country_id

 content//provider/counties/country_id/cities
 content//provider/counties/country_id/cities/city_id

 Or even like this, in addition to the above:

 content://provider/books
 content://provider/books/book_id

 A helper class, UriMatcher, can be used in ContentProvider
 implementation to quickly and easily determine what kind of data a
 request URI refers to - whether it's counties, or cities, or a country
 by its id (in the examples above).

 One the kind of data that the URI refers to is known, it's quite logical
 to store each kind of data in its own table (e.g. country / city).

 I also think it makes sense to implement separate ContentProviders for
 unrelated sets of data.

 In the example above, if you're not linking books to cities, you might have:

 content://name.Arpit.GeographyData/counties
 content://name.Arpit.GeographyData/counties/1
 content://name.Arpit.GeographyData/counties/1/cities

 ...etc... and:

 content://name.Arpit.Library/books
 content://name.Arpit.Library/books/1
 content://name.Arpit.Library/books/2

 -- Kostya

 24.08.2010 20:01, Arpit пишет:





  Hi All,

  All the example codes, tutorials or video I see, there is always one
  ContentProvider per SQL Table with the SQLiteOpenHelper extension
  defined as a private static class...

  Is it some sort of standard design...to have one ContentProvider per
  SQL Table? Or I can define one generic ContentProvider and use its
  instance for ever update?

  Is there some issue with that?

  Could anyone please help as my application has like 5-6 tables.

  Regards,
  Arpit

 --
 Kostya Vasilev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How to compile/run JUnit 4 tests in Android?

2010-08-23 Thread A. Elk
Well, it doesn't look like InstrumentationTestRunner is compatible
with JUnit4TestAdapter.

Unfortunately, a JUnit 4 test runner can't run an Android test package
against an Android app.

In short, you can't figure it out because it isn't possible.

At this point, it might be more simple to convert your JUnit 4 tests
into JUnit 3 tests. As far as I can tell, all you have to do is remove
the @Test annotations and prefix all the method names with test. You
also have to use setUp() and tearDown() instead of annotating a method
to set up or tear down a fixture.

You, of course, know best what fixtures are needed for the classes
you're trying to test with JUnit 4, but I think (naively, perhaps)
that you shouldn't have to test anything that's truly a POJO on the
device/emulator. Either the class is truly independent of Android, in
which case it shouldn't need the device, or it isn't really
independent, in which case you should run it within an Android test
case.

A.

On Aug 20, 8:33 pm, Eric e...@alum.mit.edu wrote:
 At this point I really don't understand why Android cannot run JUnit 4
 tests 'out of the box'.  There MUST be a simple way to get Eclipse/
 Android to install a JUnit 4 test runner so that when my tests run on
 the device, JUnit 4 is used.  It is discouraging that after all of the
 reading and experiments I've performed, I can't figure this out.  If
 _anyone_ out there knows how to do this, please do tell. :)

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Difference between Android Service and Content Provider

2010-08-20 Thread A. Elk
To be precise, a ContentProvider is an object that can communicate
with the ContentResolver facade. ContentProvider classes are aware of
the underlying nature of their dataset, while ContentResolver is
agnostic and provides a single interface.

A ContentProvider does not have to wrap a database. It can wrap *any*
source of data. A ContentProvider could wrap a reference librarian on
the telephone (granted, it would be very low bandwidth), although you
might find it much more useful to have the data local to the device.
Note also that ContentProvider is an abstract class, so you probably
want to implement the Big 6 Methods
(onCreate,query,insert,update,delete,getType) if you're making the
actual instance available to external developers. The method
signatures imply to the outside world that your data is organized in
tables of rows and columns. That is, the object mimics a database.
Nothing is implied about what's inside, and the external user
shouldn't have to know. To provide a ContentProvider to external
users, you should provide a contract class that defines constants
for the table and column names, the content URIs, and the available
types. Look at the Javadoc for android.provider.ContactsContract for
an example of this.

Another note: If you're only using the ContentProvider in your own
application, and you're using an SQLite database, and you have no
intention of syncing it to anything else, then you might want to skip
making a ContentProvider, and use the SQLite classes directly. I think
that the intent of ContentProvider was to make common, public datasets
available to multiple applications.

The difference between ContentProvider and Service?

ContentProvider establishes a pattern for accessing data that matches
the ContentResolver facade. This makes it easy for an application to
locate the data and access it independently of its internal form.

Service is meant to handle work-intensive tasks in an asynchronous
fashion. Nothing about data is implied. Use a Service to handle
syncing data or keeping something around to use as needed (like an
Alarm object).

Hope this helps. I apologize for hammering on ContentProvider. Just
wanted to point out that you're not limited to databases.

On Aug 20, 4:57 am, Joseph Earl joseph.w.e...@gmail.com wrote:
 It sounds like you have the right idea.

 A ContentProvider is a wrapper around your database which allows other
 applications to access and modify your database in a controlled
 manner.
 A Service is basically just a long-running task, such as downloading/
 syncing data.

 A ContentProvider would provide access to your data to your app and
 others, and you would use a Service to download the new data, which
 would then use your ContentProvider to insert that new data into your
 database.

 On Aug 19, 4:49 pm, Lily Zhang lily...@gmail.com wrote:



  I am developing an app and get confused about the idea of Service and
  Content Provider in Android. In practice, what will be the difference
  between them?

  Content Provider
  is a facade and it defines a way to share data among applications. You
  many attach a local database to your app or create Content Provider
  mapped to a universal database so that all the application on the same
  device can share it.

  Service
  is long running processes that need to be decoupled from main
  activity. It has local and remote service. local service is like the
  local database, and remote service is like Content Provider sharing
  the database info.

  What My App is doing?
  downloads info. from multiple internet resource in the background (I
  suppose this will be Service) and store the info. into database, and
  multiple applications will need to retrieve the data, format them and
  output them to user (I guess it will be a Content Provider).

  What will be the fine line between Service and Content Provider?
  Newbie in Android, and any suggestion is welcome.

  Lily

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How to compile/run JUnit 4 tests in Android?

2010-08-19 Thread A. Elk
JUnit tests Plain Old Java Objects (POJOs). Basically, it loads your
test class, runs a method, instantiates the class that you're testing,
tests the methods, does the asserts, and outputs the results. It
assumes that all the dependencies are built into the application
or .jar file or are on the classpath.

If you want to test a method in a class that subclasses an Android
class or depends on an Android class, then you have to test within the
Android framework, which is based on JUnit 3. This means that you have
to use one of the test classes in android.test.*, and you have to use
the instrumented test runner InstrumentationTestRunner (or one of its
subclasses). Instructions for doing this are in the Android 2.2 SDK
documentation under Testing and Instrumentation.

If you run something inside the emulator, you're running it in
Android, and the assumption is that it's dependent on the Android API.
For this reason, you can't test it with test cases built for JUnit 4.
However, I have to assume that since these tests are based on JUnit 4,
you wrote them prior to starting with Android, and so the classes/
methods they test do not depend on Android (or they didn't at some
point in the past).

For that reason, if you are *unit* testing these classes/methods, you
shouldn't have to use the emulator. You should be able to construct
the dependencies in the test fixture, run them with a JUnit 4 test
runner, do the asserts, and look at the results. I doubt that this is
possible within Android, because Android assumes that you're testing
under Android. So you'd have to use something other than the Dalvik
VM, which means you can't use the emulator (as far as I know). Seems
to me that chances are pretty slim that a test would pass in a non-
Dalvik VM and then fail in Android.

If the classes you want to test have any dependency on Android
classes, then you *have* to test them in Android. By the way, TFJ said
that you need to do dummy implementations of Bundle and Intent. What I
think he's saying is that you have to do this to run JUnit 4 tests in
Android. If you convert your tests to JUnit 3 style, then Android
itself provides testing implementations and environments. See the
Android 2.2 SDK that I mentioned previously.

Elk.

On Aug 19, 8:36 am, Eric e...@alum.mit.edu wrote:
 On Aug 19, 9:57 am, The.French.DJ the.french...@gmail.com wrote:

  It depends on what parts you want to test. If you need the android
  test framework classes for testing activities and services in a valid
  android context then i am not sure if you can make junit 4 work with
  it.

  However, if you extract your app logic into android independant
  classes then you can test them by having junit 4 in the classpath
  before the android jar.

 Thank you for the info.  However, what I don't understand is, will the
 JUnit 4 tests be run INSIDE the Android emulator, or outside the
 emulator on my Mac in a separate Java VM?  Ideally I want the JUnit 4
 tests to be run INSIDE the Android emulator so that I know my code
 will be 'ok' when run on an Android device.

 - Eric

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How to compile/run JUnit 4 tests in Android?

2010-08-19 Thread A. Elk
I have never tried to use vanilla JUnit 4 running under Android. I am
not absolutely certain, but I predict that it won't work. To run any
test, you need to use InstrumentationTestRunner, and it assumes JUnit
3, which is substantially different from JUnit 4. However, the
documentation for JUnit 4 says:

You make your JUnit 4 test classes accessible to a TestRunner designed
to work with earlier versions of JUnit, declare a static method suite
that returns a test.

public static junit.framework.Test suite() {
return new JUnit4TestAdapter(Example.class);
}

I'd look at the Javadoc for junit.framework.*. When I Googled it, I
saw that it included JUnit4TestAdapter. Better yet, search for help on
running JUnit 4 tests under JUnit 3. InstrumentationTestRunner is
designed to work with earlier versions of JUnit, so anything that can
convert a JUnit 4 suite to JUnit 3 should work in Android. That the
documentation for JUnit 4 includes instructions for running JUnit 4
suites under an earlier test runner implies that it's a known
situation, so I assume somebody else has written about it. Seems like
nobody else writing for Android has encountered it (or bothered to
reply), but at least for vanilla tests someone probably has done
something.

Sorry I can't help you any more.

PS - I notice that the main differences between JUnit 3 and JUnit 4
tests are a) JUnit 3 denotes a test suite by subclassing
junit.framework.TestCase (JUnit 4 has no such requirement) b) JUnit 3
test methods are denoted by the string test as the prefix of the
method name, while JUnit 4 uses the @Test annotation. It doesn't seem
to me that there are any other substantial differences, but as I have
already said, I am not a JUnit 4 expert.

On Aug 19, 3:33 pm, Eric e...@alum.mit.edu wrote:
 I absolutely want my POJO JUnit 4 tests running on the Android
 emulator VM, even if they do not reference Android APIs.  The reason
 for this is fairly clear.  Android has a different implementation of
 the base Java APIs, and it uses a special VM, so I want to know that
 all of the shared code I will take advantage of beneath the Android UI
 layer will run without fail on the emulator.

 I hate to say this, but I am _still_ confused as to whether or not
 this is possible.  Your eloquent answer didn't seem to answer the
 question specifically.  Quite simply, is it even possible to run POJO
 JUnit 4 test suites on the Android device itself, and if so, what is
 the best/quickest way to achieve this from a configuration standpoint
 in Eclipse?

 On Aug 19, 4:27 pm, A. Elk lancaster.dambust...@gmail.com wrote:

  JUnit tests Plain Old Java Objects (POJOs). Basically, it loads your
  test class, runs a method, instantiates the class that you're testing,
  tests the methods, does the asserts, and outputs the results. It
  assumes that all the dependencies are built into the application
  or .jar file or are on the classpath.

  If you want to test a method in a class that subclasses an Android
  class or depends on an Android class, then you have to test within the
  Android framework, which is based on JUnit 3. This means that you have
  to use one of the test classes in android.test.*, and you have to use
  the instrumented test runner InstrumentationTestRunner (or one of its
  subclasses). Instructions for doing this are in the Android 2.2 SDK
  documentation under Testing and Instrumentation.

  If you run something inside the emulator, you're running it in
  Android, and the assumption is that it's dependent on the Android API.
  For this reason, you can't test it with test cases built for JUnit 4.
  However, I have to assume that since these tests are based on JUnit 4,
  you wrote them prior to starting with Android, and so the classes/
  methods they test do not depend on Android (or they didn't at some
  point in the past).

  For that reason, if you are *unit* testing these classes/methods, you
  shouldn't have to use the emulator. You should be able to construct
  the dependencies in the test fixture, run them with a JUnit 4 test
  runner, do the asserts, and look at the results. I doubt that this is
  possible within Android, because Android assumes that you're testing
  under Android. So you'd have to use something other than the Dalvik
  VM, which means you can't use the emulator (as far as I know). Seems
  to me that chances are pretty slim that a test would pass in a non-
  Dalvik VM and then fail in Android.

  If the classes you want to test have any dependency on Android
  classes, then you *have* to test them in Android. By the way, TFJ said
  that you need to do dummy implementations of Bundle and Intent. What I
  think he's saying is that you have to do this to run JUnit 4 tests in
  Android. If you convert your tests to JUnit 3 style, then Android
  itself provides testing implementations and environments. See the
  Android 2.2 SDK that I mentioned previously.

  Elk.

  On Aug 19, 8:36 am, Eric e...@alum.mit.edu wrote:

   On Aug

[android-developers] Re: POJO junit test in an Android project

2010-08-10 Thread A. Elk
The JUnit TestCase in Android should work.

By default, the Eclipse plug-in will not build tests/ or its
subdirectories into your application's .apk.

I recommend you have one project for your main application, and
another *project* for your test package. Notice that two different
projects in Eclipse can point to the same directory structure. The
project for your main application will point to root/src, root/
res, etc. The project for your test package will point to root/tests/
src, root/tests/res, etc. The same value of root is used for both
projects.

You can do this with the Android New Project wizard or Android New
Test Project wizard (in SDK 2.2 at least). When you create the test
project's location, uncheck default location and then enter root/
tests

What problem are you running into when you try to run a test package
containing subclasses of junit.framework.TestCase? You need to run it
with InstrumentationTestRunner. See the Android 2.2 documentation
Testing and Instrumentation and also Testing in Eclipse, with ADT.
Or, you can use AndroidTestCase, which extends
junit.framework.TestCase.


On Aug 10, 4:33 am, ko5tik kpriblo...@yahoo.com wrote:
 On Aug 10, 3:39 am, doug doug_a...@yahoo.com wrote:

  Oh well, It doesn't seem that the Eclipse plug-in would even run a
  test case subclassed directly from junit.framework.TestCase.  How do
  folks test POJOs in Android then?

 Which junit.framework.TestCase you are using?   One coming from
 android library
 will be just a stub

 I use jMockit to mock everything android in my testcases, and junit
 coming from somewhere else

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Support for JUint Annotation

2010-08-06 Thread A. Elk
Android uses JUnit 3.

On Aug 6, 5:56 am, nikki nikhileshsingh...@gmail.com wrote:
 hi group

 Do android support JUnit4 annotations like @Test...?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Android testing: can't programmatically press buttons, etc...

2010-08-06 Thread A. Elk
Can you attach some code snippets from your test app? Are you using
clickView() or tapView()?

You must call setActivityInitialTouchMode(true) before you do a
startActivity(). Seems that you're doing this if you call it in
setUp(), although I could be wrong.

Unfortunately, I'm not familiar with Robotium.

Instrumentation should be able to feed touch events to the Activity.
Notice that the test method that you use for this must run on the UI
thread, but you should already see that if you're not doing it. To do
it, you use @runOnUIThread for the entire method, or use a Runnable
for just a small subset of statements. This is documented in the SDK
2.2 documentation under Testing and Instrumentation. There's a section
in that topic called Testing on the UI Thread that has some
examples.

On Aug 5, 11:59 pm, Fabrizio Giudici fabrizio.giud...@tidalwave.it
wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 8/5/10 19:11 , A. Elk wrote:

  In other words, you can do button presses in a sample Android
  app from a test package, but you can't do them from your app's
  test package to the app under test.

 Right.

  (The test package is the same as the test app and the app under
  test is the application you're trying to build.)

  Are you using ActivityInstrumentationTestCase2 as your test case
  class? I assume that you're calling TouchUtils.clickView(t,v)
  where

  t is the test case object (probably _this_), and v is the Button
  object you want to click, in the Activity you're testing in the
  app under test.

 I'm trying _also_ with TouchUtils.clickView(); I'm also exploring
 other testing frameworks. The cited Robotium, for instance, creates
 MotionEvents with the DOWN/UP sequence and the proper position and
 feeds them to the Instrumentation (yes, I'm using AITC2). I've
 manually verified that the events are properly created (uptime,
 coordinates are ok - tested with the hierarchyviewer - etc).

 Yesterday night I discovered that tests launched my application not in
 touch mode (in fact, I could see a focused button in orange). This
 would have been an explanation, but then I explicitly added
 setActivityInitialTouchMode(true) in setUp(), I got a visual
 confirmation that it has been accepted (I no more see a focused
 button), but it's not yet working.

 - --
 Fabrizio Giudici - Java Architect, Project Manager
 Tidalwave s.a.s. - We make Java work. Everywhere.
 java.net/blog/fabriziogiudici -www.tidalwave.it/people
 fabrizio.giud...@tidalwave.it
 -BEGIN PGP SIGNATURE-
 Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
 Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/

 iEYEARECAAYFAkxbsrYACgkQeDweFqgUGxfhaACfZpiS5INwfKXAHoblnkbGammP
 dbwAn0WuoLcxXkTbDzj8qRORCEVZQaUf
 =3h7h
 -END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How to use JUnit test Android Project?

2010-08-05 Thread A. Elk
Are you testing with a standard JUnit project, or with an Android
JUnit project?

Please note that standard JUnit will only work with plain Java
objects. If you need to test anything that calls the Android API, you
should use AndroidTestCase as the test case class and use
InstrumentationTestRunner as your test runner. SDK 2.2 documentation
contains instructions for setting up an Android JUnit test project.

If your application depends on another project, be sure to export the
classes from the 3rd project, otherwise JUnit might not be able to see
them. Search this group; somebody else asked about a similar problem
yesterday. You need to export classes in the Java Build Path section
of the project settings.

On Aug 4, 9:24 pm, CaryWang wangjf...@gmail.com wrote:
 I want use JUnit test my project,but sometime test
 error(java.lang.IllegalAccessError: cross-loader access from pre-verified
 class).Because my project import another java project.I don't know how to
 do?

 --
 Cary

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Testing a service

2010-08-05 Thread A. Elk
Are you using ServiceTestCase? If one is testing a Service, by far the
best way to do it is to use ServiceTestCase as the test case class.
Use InstrumentationTestRunner as the test runner. Android testing
using instrumentation is documented in SDK 2.2. See *Framework Topics*
and *Developing*. There's also a tutorial in the *Reference* tab.

ServiceTestCase has a startService(Intent) method.

On Aug 5, 2:40 am, nikhilesh singh tak nikhileshsingh...@gmail.com
wrote:
 yes like that only... but i want to start the service from my test 
 application.





 On Thu, Aug 5, 2010 at 2:44 PM, Jeroen Kransen jer...@kransen.nl wrote:
  Something like this from an Activity:

  startService(new Intent(this, RemoteSynchronizer.class));

  Jeroen

  On 5 aug, 11:08, nikki nikhileshsingh...@gmail.com wrote:
  hi Elk

  thanks for the reply.

  I am able to start the service when i specify an implicit intent to
  start the service but i am not getting any clue on how to start the
  service with the explicit intent i.e. actually specifying the service
  class.

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

 --
 Nikhilesh Singh Tak

 +91-9630934374
 +91-9929098279

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Android testing: can't programmatically press buttons, etc...

2010-08-05 Thread A. Elk
In other words, you can do button presses in a sample Android app
from a test package, but you can't do them from your app's test
package to the app under test.
(The test package is the same as the test app and the app under
test is the application you're trying to build.)

Are you using ActivityInstrumentationTestCase2 as your test case
class? I assume that you're calling TouchUtils.clickView(t,v) where

t is the test case object (probably _this_), and v is the Button
object you want to click, in the Activity you're testing in the app
under test.



On Aug 5, 9:24 am, Fabrizio Giudici fabrizio.giud...@tidalwave.it
wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 8/5/10 17:56 , Brion Emde wrote: Did you try working with the testing 
 tutorial?

 http://developer.android.com/resources/tutorials/testing/activity_tes...

 That gives an example of using the Instrumentation to send key presses

  to an Activity.

 Yes, I've been able to run example tests both from vanilla Android and
 from Robotium - they work. For what I've checked (multiple times) the
 set up, manifest, etc... are properly configured in my app. I don't
 know what to check more, that's why I'd like to know whether there's
 some kind of system diagnostics to understand what's happening.

 - --
 Fabrizio Giudici - Java Architect, Project Manager
 Tidalwave s.a.s. - We make Java work. Everywhere.
 java.net/blog/fabriziogiudici -www.tidalwave.it/people
 fabrizio.giud...@tidalwave.it
 -BEGIN PGP SIGNATURE-
 Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
 Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/

 iEYEARECAAYFAkxa5cYACgkQeDweFqgUGxee1ACfYErl7SuHOHq9GXAWO8A1Gwjx
 GVkAn27QZt7aZTV8qWxYgJs1Ze4u2UGv
 =lvr2
 -END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: AndroidTestCase fails with dependency on third project

2010-08-04 Thread A. Elk
I'm a bit confused here. You say that the tests run successfully in
the emulator, correct? Is this under Eclipse?

It looks as if you're getting class resolution errors in the Loader.
I'm not sure why this is happening, but I would guess that the class
loader is seeing the library classes in your test package, not your
main application. These classes may be out of sync with the classes
expected by the main application. Remember that in a test, you're
running both test and app in the same process, so the loader may not
try to load library classes twice.

Build the library into the main app and export the classes, and then
(I think this is right) make the test project dependent on the main
app but *not* the library project. I think that should work.

A.


On Aug 4, 2:45 am, Jeroen Kransen jer...@kransen.nl wrote:
 I have a and Android project and its test project. I can run tests
 successfully in the emulator. As the Android project has dependencies
 on a third library project, I want to use classes of the third project
 in the test cases too. For this, I need to add a dependency from the
 test project to the third project as well. Compile-time this works,
 but when I do a remote run of my AndroidTestCase, all tests fail. For
 each test, I get a NoClassDefFoundError, but not for third project
 classes, but for a class in the Android project itself!

 In the LogCat I also get very interesting messages:

 08-04 09:27:35.163: WARN/dalvikvm(817): Class resolved by unexpected
 DEX: Lnl/kransen/consumption/android/dao/MeasurementDaoImpl;
 (0x43d0c940):0x136900 ref [Lnl/kransen/consumption/dao/
 MeasurementDao;] Lnl/kransen/consumption/dao/MeasurementDao;
 (0x43d0c940):0x116b20
 08-04 09:27:35.163: WARN/dalvikvm(817): (Lnl/kransen/consumption/
 android/dao/MeasurementDaoImpl; had used a different Lnl/kransen/
 consumption/dao/MeasurementDao; during pre-verification)
 08-04 09:27:35.172: INFO/dalvikvm(817): Failed resolving Lnl/kransen/
 consumption/android/dao/MeasurementDaoImpl; interface 127 'Lnl/kransen/
 consumption/dao/MeasurementDao;'
 08-04 09:27:35.172: WARN/dalvikvm(817): Link of class 'Lnl/kransen/
 consumption/android/dao/MeasurementDaoImpl;' failed
 08-04 09:27:35.172: ERROR/dalvikvm(817): Could not find class
 'nl.kransen.consumption.android.dao.MeasurementDaoImpl', referenced
 from method
 nl.kransen.consumption.android.test.MeterstandenDaoImplTest.setUp
 08-04 09:27:35.182: WARN/dalvikvm(817): VFY: unable to resolve new-
 instance 41 (Lnl/kransen/consumption/android/dao/MeasurementDaoImpl;)
 in Lnl/kransen/consumption/android/test/MeterstandenDaoImplTest;
 08-04 09:27:35.182: DEBUG/dalvikvm(817): VFY: replacing opcode 0x22 at
 0x000c
 08-04 09:27:35.192: DEBUG/dalvikvm(817): Making a copy of Lnl/kransen/
 consumption/android/test/MeterstandenDaoImplTest;.setUp code (64
 bytes)
 08-04 09:27:35.192: WARN/dalvikvm(817): Class resolved by unexpected
 DEX: Lnl/kransen/consumption/android/dao/MeasurementDaoImpl;
 (0x43d0c940):0x136900 ref [Lnl/kransen/consumption/dao/
 MeasurementDao;] Lnl/kransen/consumption/dao/MeasurementDao;
 (0x43d0c940):0x116b20
 08-04 09:27:35.203: WARN/dalvikvm(817): (Lnl/kransen/consumption/
 android/dao/MeasurementDaoImpl; had used a different Lnl/kransen/
 consumption/dao/MeasurementDao; during pre-verification)
 08-04 09:27:35.203: INFO/dalvikvm(817): Failed resolving Lnl/kransen/
 consumption/android/dao/MeasurementDaoImpl; interface 127 'Lnl/kransen/
 consumption/dao/MeasurementDao;'
 08-04 09:27:35.213: WARN/dalvikvm(817): Link of class 'Lnl/kransen/
 consumption/android/dao/MeasurementDaoImpl;' failed
 08-04 09:27:35.222: WARN/dalvikvm(817): Class resolved by unexpected
 DEX: Lnl/kransen/consumption/android/dao/MeasurementDaoImpl;
 (0x43d0c940):0x136900 ref [Lnl/kransen/consumption/dao/
 MeasurementDao;] Lnl/kransen/consumption/dao/MeasurementDao;
 (0x43d0c940):0x116b20
 08-04 09:27:35.222: WARN/dalvikvm(817): (Lnl/kransen/consumption/
 android/dao/MeasurementDaoImpl; had used a different Lnl/kransen/
 consumption/dao/MeasurementDao; during pre-verification)
 08-04 09:27:35.222: INFO/dalvikvm(817): Failed resolving Lnl/kransen/
 consumption/android/dao/MeasurementDaoImpl; interface 127 'Lnl/kransen/
 consumption/dao/MeasurementDao;'
 08-04 09:27:35.222: WARN/dalvikvm(817): Link of class 'Lnl/kransen/
 consumption/android/dao/MeasurementDaoImpl;' failed
 08-04 09:27:35.232: INFO/dalvikvm(817): Could not find method
 nl.kransen.consumption.android.dao.MeasurementDaoImpl.close,
 referenced from method
 nl.kransen.consumption.android.test.MeterstandenDaoImplTest.tearDown
 08-04 09:27:35.232: WARN/dalvikvm(817): VFY: unable to resolve virtual
 method 80: Lnl/kransen/consumption/android/dao/
 MeasurementDaoImpl;.close ()V
 08-04 09:27:35.232: DEBUG/dalvikvm(817): VFY: replacing opcode 0x6e at
 0x0002
 08-04 09:27:35.244: DEBUG/dalvikvm(817): Making a copy of Lnl/kransen/
 consumption/android/test/MeterstandenDaoImplTest;.tearDown code (28
 bytes)
 08-04 09:27:35.244: 

  1   2   >