MzelleNeskimo Posted June 7, 2010 Share Posted June 7, 2010 Bonjour à vous! Je suis en train de faire les tests unitaires de mon application, je tâtonne au fur et à mesure. Je voudrais tester la suppression d'un utilisateur J'arrive à tester ma liste, choisir un des éléments, sélectionner la suppression et donc lancer l'AlertDialog, et j'aurais aimé savoir comment faire pour paramétrer la réaction à un choix. Le code de l'Activity à tester ou est défini l'alerte : case R.id.supprimer: v.setBackgroundColor(getContext().getResources().getColor(R.color.rouge)); // ** Creation of the AlertDialog to confirm the suppression new AlertDialog.Builder(getContext()) .setTitle("Confirmation") .setMessage(getContext().getString(R.string.remove_confirm)) // ** value of the positive button .setPositiveButton(getContext().getString(R.string.oui), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //Log.v("onClick", "TODO@Delete: " + (CheckedRecipient)((View)v.getParent()).getTag()); deleteRecipient((CheckedRecipient)((View)v.getParent()).getTag()); } }) // ** negative button .setNegativeButton(getContext().getString(R.string.non), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // ** nothing is done } }) .show(); break; Le code de la classe de test ou je veux valider ou annuler l'alerte sachant que j'utilise ActivityInstrumentationTestCase2 (surtout car c'était celui utilisé dans le tuto de google) public void testDelete() { Log.w("testDelete", "Debut"); mActivity.runOnUiThread( new Runnable() { public void run() { for(int i=0; i // --- Select second item mListView.setSelection(i); Log.v("testDelete@run", "SelectedItemPosition: "+mListView.getSelectedItemPosition()); assertEquals(i, mListView.getSelectedItemPosition()); mRecipientRowView = mListView.getAdapter().getView(mListView.getSelectedItemPosition(), null, mListView); Log.d("testDelete@run", "RecipientRowView: "+mRecipientRowView); } //Delete the last TextView mRecipient = (TextView)mRecipientRowView.findViewById(com.almerys.psm.ha.android.activity.R.id.textRecipient); ImageView mIcon = (ImageView)mRecipientRowView.findViewById(com.almerys.psm.ha.android.activity.R.id.iconeRec); Log.d("testDelete@run", "TextViewRecipient: "+mRecipient); Log.d("testDelete@run", "TextViewRecipientText: "+mRecipient.getText()); Log.d("testDelete@run", "ImageViewIcon: "+mIcon); mSuppr = (ImageButton)mRecipientRowView.findViewById(com.almerys.psm.ha.android.activity.R.id.supprimer); Log.d("testDelete@run", "ImageButtonSuppr: "+mSuppr); // --- Perform click boolean isClickPerformed = mSuppr.performClick(); Log.d("testDelete@run", "performClickOnDelete: "+isClickPerformed); assertTrue(isClickPerformed); } } ); mInstrumentation.waitForIdleSync(); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.v("testDelete", "Fin"); } Merci d'avance à tous ceux qui pourront m'aider Edit Jorodan : Utilise la balise code de préférence ;) Link to comment Share on other sites More sharing options...
popolbx Posted June 7, 2010 Share Posted June 7, 2010 méthode rache : les tests unitaires ça sers que dans les livres........^ Link to comment Share on other sites More sharing options...
Burn2 Posted June 7, 2010 Share Posted June 7, 2010 Message promu par la team arrache style system company! :D Link to comment Share on other sites More sharing options...
MzelleNeskimo Posted June 7, 2010 Author Share Posted June 7, 2010 Si seulement je pouvais m'en passer... Personne personne n'en a fait? Link to comment Share on other sites More sharing options...
MzelleNeskimo Posted June 14, 2010 Author Share Posted June 14, 2010 Double post mais pour la bonne cause. J'ai trouvé comment faire finalement. Dans le code de mon application j'ai du ajouter un get sur mon dialogue pour pouvoir le récupérer dans mon appli de test, c'est pas très propre mais bon... Et du coup dans le test, je récupère ensuite les boutons oui/non et je simule le click. Donc si certains son intéressés : AlertDialog alertD = recipientAdapter.getAlertD(); // récupérer l'alertDialog à partir de l'adapter Button val, can; val=alertD.getButton(DialogInterface.BUTTON_POSITIVE); // récupérer le bouton oui can=alertD.getButton(DialogInterface.BUTTON_NEGATIVE); // le bouton non val.requestFocus(); // mettre le focus sur le oui val.performClick(); // simuler le oui Tadam ça marche! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.