tag:blogger.com,1999:blog-25456655.post4491241648374674116..comments2024-03-23T07:01:55.848-04:00Comments on Diego Torres Milano's blog: Android Application Testing Guide: Q&ADiego Torres Milanohttp://www.blogger.com/profile/12030778501784140349noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-25456655.post-65979228830991975562021-01-07T05:25:20.093-05:002021-01-07T05:25:20.093-05:00These days, id verification service is greater in ... These days, id verification service is greater in demand. Trust Swiftly is truly the only platform that offers numerous verification systems, and a corporation can grant a lot better safety to their business by making use of all of the verification solutions. By going to this unique <a href="https://trustswiftly.com/" rel="nofollow">trustswiftly</a> site, you can obtain more knowledge about id verification service. <br />Verify Customer Identityhttps://www.blogger.com/profile/00111716140522589187noreply@blogger.comtag:blogger.com,1999:blog-25456655.post-32315938309171288432012-03-08T02:03:39.768-05:002012-03-08T02:03:39.768-05:00Hi Chuck,
This is a very interesting question. Som...Hi Chuck,<br />This is a very interesting question. Sometime, depending on the situation I have used what you describe as <b>1</b>. This gives you the advantage of having an implicit timeout.<br /><br />In other cases where this solution is not the most appropriate I would recommend using a latch (i.e. <a href="http://developer.android.com/reference/java/util/concurrent/CountDownLatch.html" rel="nofollow">CountDownLatch</a>).<br /><br />Your test would be something like this:<br /><i><br /> public void testAsyncTaskFinished() throws Throwable {<br /> final AsyncTaskActivity activity = getActivity();<br /> activity.getLatch().await(TIMEOUT, TimeUnit.MILLISECONDS);<br /> assertTrue("finish".equals(activity.getResult()));<br /> }<br /></i><br />It's true, this adds some extra code only intended to ease testing but it's minimal. You have to create the accessor for the latch and initialize it when the task is started (i.e. onPreExecute()) and decrement its value when task is finished (i.e. onPostExcecute()).<br /><br />I will be creating a post detailing this solution because I think it would help other people and formatting here is very confusing.Diego Torres Milanohttps://www.blogger.com/profile/12030778501784140349noreply@blogger.comtag:blogger.com,1999:blog-25456655.post-55418142556087326412012-03-05T17:38:38.079-05:002012-03-05T17:38:38.079-05:00Bought the book and read it. Now I'm diving i...Bought the book and read it. Now I'm diving in and trying to apply what I've learned to my first project and I've hit a wall with how to test a method that performs tasks on a worker thread. The jUnit test calls the program but doesn't wait for the other thread to complete before asserting that everything that should happen has happened. Here is the method invoked:<br /><br /> public void mapButtonClicked()<br /> {<br /> String aZipcode = m_View.getZipcodeEntered();<br /> m_View.clearAllMapOverlays();<br /> if (aZipcode.isEmpty())<br /> {<br /> m_View.displayToastMessage(TOAST_NO_ZIP_ENTERED, Toast.LENGTH_SHORT);<br /> }<br /> else<br /> {<br /> m_View.hideZipcodeTextViewSoftKeys();<br /> m_AddContactsToMapTask = new AddContactsToMapTask();<br /> m_AddContactsToMapTask.execute(new String[] { aZipcode }); // <------ here is the AsyncTask that is invoked on a worker thread<br /> }<br /> }<br /><br />in jUnit my test is structured as:<br /><br /> public void testMapButtonClicked() <br /> {<br /> m_Controller.mapButtonClicked();<br /> // followed by asserts to check the results which get checked before the thread has completed<br /> }<br /><br />Since nearly all Android apps must perform long running tasks on worker threads, my need to validate that multi-threaded activities perform the actions expected cannot be unique. I have tried:<br /><br /> 1) sleep for a few seconds, this is unreliable as the thread may take longer and it also makes the tests run very slowly, a bad thing<br /> 2) create a boolean semaphore to indicate completion and loop the test until true - this means that there is code in the app only used for testing, also a bad thing<br /><br />Your suggestions would be greatly appreciated. Have you seen a good design pattern for testing the results of worker thread activities? Can you point me in a direction or to some resource? I searched and searched the web with no luck so far.Chuck Krutsingerhttps://www.blogger.com/profile/07719458449455589539noreply@blogger.comtag:blogger.com,1999:blog-25456655.post-60380486576564550672011-11-28T13:30:16.254-05:002011-11-28T13:30:16.254-05:00Hi Pedro,
You need the Interface to be able to cre...Hi Pedro,<br />You need the Interface to be able to create a mock, so in your case I guess you need<br /><br><br /> ITelephony telMan = createMock(ITelephony.class);<br /> telMan.call("555-1234");<br /><br><br />but unfortunately ITelephony is hidden<br /><br><br />/**<br /> * Interface used to interact with the phone. Mostly this is used by the<br /> * TelephonyManager class. A few places are still using this directly.<br /> * Please clean them up if possible and use TelephonyManager insteadl.<br /> *<br /> * {@hide}<br /> */<br />interface ITelephony {<br />...<br />}<br /><br><br />so you won't be able to do this from the SDK.Diego Torres Milanohttps://www.blogger.com/profile/12030778501784140349noreply@blogger.comtag:blogger.com,1999:blog-25456655.post-48419878146356609382011-11-28T11:53:42.195-05:002011-11-28T11:53:42.195-05:00Hi Diego. I'm trying to use easymock on Teleph...Hi Diego. I'm trying to use easymock on TelephonyManager like this:<br /><br />TelephonyManager telman = createMock(TelephonyManager.class);<br /><br />but I always get this error:<br /><br />java.lang.IllegalArgumentException: android.telephony.TelephonyManager is not an interface<br />at java.lang.reflect.Proxy.getProxyClass(Proxy.java:109)<br /><br /><br />Do you have any idea why this happens or what I'm doing wrong?Anonymoushttps://www.blogger.com/profile/16326849732526502958noreply@blogger.comtag:blogger.com,1999:blog-25456655.post-74138494434856555232011-08-08T07:05:01.762-04:002011-08-08T07:05:01.762-04:00Very complete answers, thanks a lot Diego ;)Very complete answers, thanks a lot Diego ;)Anonymoushttps://www.blogger.com/profile/16326849732526502958noreply@blogger.comtag:blogger.com,1999:blog-25456655.post-8816318343138539332011-08-05T10:55:29.622-04:002011-08-05T10:55:29.622-04:00Detailed answer available in this post.Detailed answer available in this <a href="http://dtmilano.blogspot.com/2011/08/android-application-testing-guide-q_05.html" rel="nofollow">post</a>.Diego Torres Milanohttps://www.blogger.com/profile/12030778501784140349noreply@blogger.comtag:blogger.com,1999:blog-25456655.post-5611311644651864692011-08-04T17:53:22.292-04:002011-08-04T17:53:22.292-04:00Thanks Pedro for your question that will help me i...Thanks Pedro for your question that will help me improve the book's content.<br /><br />A method like this would do the trick:<br /><br><br /> private void assertLoadUrl(String url) {<br /> mWebView.loadUrl(url);<br /> sleep();<br /> assertTrue(!(mWebView.getProgress() < 100));<br /> }<br /><br><br />sleep() just calls Thread.sleep().<br />If you need to detect errors you may need to create a MockWebViewClient.Diego Torres Milanohttps://www.blogger.com/profile/12030778501784140349noreply@blogger.comtag:blogger.com,1999:blog-25456655.post-79613757128672648922011-08-03T14:25:58.752-04:002011-08-03T14:25:58.752-04:00Diego, if we were to test something that is asynch...Diego, if we were to test something that is asynchronous, like in my case I'm wanting to test if a webview loads an URL how would I go about waiting for the webpage to finish loading in my webview ?<br /><br />I've found this while surfing the web : http://code.google.com/p/awaitility/ , would this be a good solution?Anonymoushttps://www.blogger.com/profile/16326849732526502958noreply@blogger.com