0

I want to make a suite to test my webservice calls in an Android app. They extend AsynchTask.

I don't want to change my api to offer synchronous calls.

I tried already with JUnit / Android test project. The methods are run through but the callbacks never executed.

In order to use the test project setup, which at least manages to add the dependencies of the original project well, I made hacks. Kept using TestCase subclass but instead of using test methods, I called manually custom test methods from within setUp() method and instead of using JUnit's asserts I outout debug messages to the Log. I even added a test Method which calls a Thread.sleep(10000), for the case the callbacks are not executed because the class finishes to fast. Guess what, also didn't work. The callbacks are still never executed. I get Log messages before, but the log messages in the callbacks never appear.

I also tried a plain Java project. But this also didn't work, because of the AsynchTask and some other Android classes. Adding Android as a library to the Java project didn't work because the Android library is "stubbed" and only supposed to be used inside an Android project, as far I read researching.

So what do I do to test these webservices? I could test the webservices alone with plain Java project. But I would like to test my wrapper classes, which build the parameters and so on. But these wrapper classes are coupled with android library and AsynchTask and there's no way to change that.

User
  • 31,811
  • 40
  • 131
  • 232
  • It sound like you need a better OO design for your project, see if my answer [here](http://stackoverflow.com/questions/8295003/best-way-to-manage-the-progressdialog-from-asynctask/8317071#8317071) helps. – yorkw May 07 '12 at 09:51
  • these are .net web services or java? – Rajiv yadav May 07 '12 at 10:01
  • Why do you need to know which kind of web services they are? – User May 07 '12 at 10:15
  • @yorkw I use callbacks in order to react to the responses of these Webservices. How do I make a generic interface (which would be also used for testing) which support callbacks in the asynchronous case? – User May 07 '12 at 10:19
  • @lxx after that i would be able to tell you tool for testing web services. – Rajiv yadav May 07 '12 at 10:22
  • 1
    @yorkw I think I know the way. Webservice class only business logic (call webservices synchronous and return answer), and the AsynchTask is a wrapper that runs this in execute, and passes the answer to the callback when done. Have to elaborate it. – User May 07 '12 at 10:29
  • @Rajiv it's a PHP webservice. – User May 07 '12 at 10:30
  • @lxx i am using wcf(.net) and testing these with wcfclient. you may use http://phpwebservices.blogspot.in/2008/01/simplest-php-web-service-client.html – Rajiv yadav May 07 '12 at 10:40
  • @Rajiv it's not necessary to test the webservice also in PHP. It can be tested in any language. Another thing is I don't want to test only the service. I want to test my methods which are building the parameters and calling the service. – User May 07 '12 at 11:05
  • @Ixx, Yes, BusinessDAO as its name stated, should focus on how business logic is implemented to produce most general API, where, when and how API get called are determined by consumer code, i.e. if API is used in an Android Application, called it off the UI thread, for instance, via AsyncTask. Same, unit-test businessDAO should focus on if the business logic is properly implemented, not where, when and how it get called, synchronously or asynchronously. – yorkw May 07 '12 at 23:12
  • Test your web service response using Junit now...http://findnerd.com/list/view/Testing-Web-Service-response-using-Junit-in-Android/3193/ – Rohit Goswami May 29 '15 at 06:35

0 Answers0