File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes Is there another android unit testing framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Is there another android unit testing framework" Watch "Is there another android unit testing framework" New topic
Author

Is there another android unit testing framework

John Johner
Greenhorn

Joined: Apr 04, 2014
Posts: 2
From what I've read, it is possible for Robolectricto intercept the Http Requests that the application in testing does. So I initially planned to capture these Http Requests and then modify their values by intercepting the http responses through another Robolectric method .setDefaultHttpResponse. The problem is, I am using Robotium already in the app and I need these integration tests and Robolectric does not run on android devices mainly because of this Log I received :



I really needed Robolectric's feature to capture outgoing http requests. That is the only thing I need from it. So knowing that it will not go well with my current implementation of my test cases and how I need them, I am kind of lost how else I am going to test them. My app has different architecture that is quite not unit test ready and I can't modify it's code. It sends HttpRequests on it's onCreate method and it will then modify the layout depending on what the http response is.

Are there any frameworks that could do this that would go well with robotium integration tests?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Roboelectric looks like it is not supposed to be running on the emulator/phone... its purpose is so you can unit test the application in a normal Java environment without having to go to the phone. So the fact that you are trying to run it on the phone is using the framework incorrectly.

So you have two solutions: 1) use Roboelectric on the desktop the way it is supposed to run or 2) use a mocking framework to get the tests to run on the device the way you want. I think Mockito would work with either framework for running HTTP request (Apache HtttpClient or HttpURLConnection).


Steve
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Two things I forgot:

1) Welcome to the Ranch!

2)
John Johner wrote:It sends HttpRequests on it's onCreate method and it will then modify the layout depending on what the http response is.

I hope you are not calling the HttpRequest on the same thread as onCreate/the UI! This will lead to poor responsiveness and possible a warning to your users that the application has hung when the data connection is slow. What you should be doing is displaying some default UI components immediately and starting an AsyncTask which does the web communication, then feeds the changes that need to be made back to the UI thread so Android doesn't think your app is frozen.
John Johner
Greenhorn

Joined: Apr 04, 2014
Posts: 2
Steve Luke wrote:Two things I forgot:

1) Welcome to the Ranch!

2)
John Johner wrote:It sends HttpRequests on it's onCreate method and it will then modify the layout depending on what the http response is.

I hope you are not calling the HttpRequest on the same thread as onCreate/the UI! This will lead to poor responsiveness and possible a warning to your users that the application has hung when the data connection is slow. What you should be doing is displaying some default UI components immediately and starting an AsyncTask which does the web communication, then feeds the changes that need to be made back to the UI thread so Android doesn't think your app is frozen.


Yes I am using another thread to do the HttpRequest. If it wouldn't be too much, may I ask for a link on how I can use Mockito to catch http requests/responses from our server?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there another android unit testing framework