samedi 28 février 2015

how to test a functionality when an event occurs in Eclipse Android



I have an already working Android App developed in Eclipse. I am testing the app using test case methods using JUnit. I am new to the Unit Testing in JAVA Android.


My question is, in my app, when I press a button, an alert box appears and I want to test it and show that the test passes (that is, the alert box appears each time the user presses the button). I notice that all the tests are run immediately after the app is installed on my phone.


Since, it is a click event in my app of a button, how do I make the test method run when I click on the button. Any help is highly appreciated. Just a generic suggestion could help a lot. In the code, I want to test if an alert box appears when a button is clicked. The test method is



// Method to check if a message box appears when the button is clicked
public void testifbutton_works() {

}


So, I want to write code in this method that checks if an alert box opens when the user clicks on the button. I notice that all the test methods run when at the start of the app. Any idea how to make this work only when the button is clicked?




Aucun commentaire:

Enregistrer un commentaire