espresso times out on CookieManager.getInstance().setCookie(name, value) - android

I'm writing an espresso test for a login activity that sets cookies:
CookieManager.getInstance().setCookie(name, value)
But the test hangs at the above code then times out. Looking into the setCookie code I think it calls some native jni method.
I can't try setCookie(name, value, callback) because the code needs to support API level 19.
Any idea why this is happening?
Many thanks!
Update: just to add that this seems to only happen when test is run against emulator. It runs without problem against a real device.

Related

Observable.then() not working on real device

I have an Ionic app that correctly works in the IonicLab, both while running and debugging it.
The same code, when run or debugged on a real Android device, fails to initialize the argument in one of the then() callbacks of an Observable. Most other (I suspect all other) Observable instances around my code do work correctly.
If I were to guess the cause, I'd say that non-working-on-real-device Observable is too nested into a chain of enclosing Promises, but that's just a random guess by a random Angular newbie.
Here is what I see when I debug the app attached to the real Android device:
As you can see, the profile variable is undefined, but, as I understand how Observable.then() works, it should have a value, as it in fact does have when run in the IonicLab.
What am I missing?

Firebase test lab showing unexpected test failures

I've started using Firebase Test Lab recently with espresso. All the test cases pass on my local device but when it comes to testing devices present on google cloud, some test cases fail with exceptions like "NoMatchingViewException". I've tried increasing the wait time before the test runs and the fragment loads, but that too does not seem to help. Please help if you know how to resolve this issue. Thank you!
I had the same problem when I tried my app. The problem is that I used UDPSocket in my application.. kinda weird but there was this exception thrown : NoMatchingViewException.
So, I Mocked the UDP call. So at least I was able to do the UI automated test.

Android Espresso tests never finish

I've been struggling with getting instrumented unit tests properly working for my android project, as when I make a test class and use ActivityTestRule to run my activity, each individual test runs - but despite returning either as a success or failure, the test just never ends.
Everything works as intended, but the tests don't end, and so each test has to be ran on its own, then manually ended.
Does anyone have any idea why this might be the case?
Found out the problem, scottymack pointed me in the right direction - I had a thread that constantly updated a View, and for some reason, ActivityTestRule didn't call onPause and onDestroy methods that would normally be called on shutdown. All it took was putting those in an #After method.

Android: How to do (automated) functional testing of Location Services

The app that I am working, is driven by Location Services. Driving with phone hooked to laptop is not always practical (and getting complex).
How would I write automated functional test for my app (googling shows UI related testing)? I understand that I need to inject values into following callback (since my app is driven by Location Manager)
#Override
public void onLocationChanged(Location location) {}
In a java application, I would create a unit that would have instance of my application and invoke the methods. But,
a) How would I do it for Android App (where there is no main method and everything is driven by onCreate())
b) How does it change, if above functionality is part of Android Service
Where we work, we use PowerMockito. I'm not a super fan of it, but I totally understand your frustration with unit tests. Here's a decent tutorial for the topic: http://www.johnmullins.co/blog/2015/02/15/beginners-guide-to-using-mockito-and-powermockito-to-unit-test-java/
Basically, what PowerMockito lets you do is write a bunch of Powermock unit tests. Those tests are going to let you mock the responses, and let you test your code. You can even manually call "onLocationChanged".
The reason I don't like PowerMockito is that that means you have to act like the Android OS. You can make dummy location responses and test to see if your code does the right thing, but it's much harder to test the code with field conditions. If a particular phone has an issue with the locations its returning, PowerMock is never going to help you catch it.
Use MockLocationProvider in android genymotion emulator.
See below link:-
https://mobiarch.wordpress.com/2012/07/17/testing-with-mock-location-data-in-android/

Android Force Close Uncatchable Unreportable

I've released my second game project on the Android Market this week, and immediately had multiple 1-star reports due to force closes. I tested it on many handsets and many emulators with zero issues. I'm completely at a loss for how to proceed and looking for advice.
I use Thread.setDefaultUncaughtExceptionHandler to intercept and report uncaught exceptions, then close gracefully. The people reporting force closes aren't getting to any of that, even though it is the first thing set in the application's main task constructor, and everything is wrapped in try/catches throughout. They are also reporting that there is no "Send Report" option in the force close popup (providing the Developer Console error reports), so I have absolutely no way of knowing what the problem is.
Uses Android 2.0, with android:minSdkVersion="5". Only Permission required is INTERNET.
(on Android market as 'Fortunes of War FREE' if you want to test)
I'm a bit surprised about the missing "Send report" button. What API level did you build the game with? I usually build the level with your minimum API level to make sure you're not using any API calls beyond that, but then switch back to the highest API level so you can use functionality like "install to SD".
I'm sure there's at least one user who wrote you a mail. Can you ask them to install LogCollector and mail you the log?
Btw, in general, I wouldn't use Thread.setDefaultUncaughtExceptionHandler so there IS the option to send a report. (It's ominously missing in your case, but normally, it should be there.)
Btw btw, the exception handler applies to the current thread. If you have an OpenGL app, maybe the crash happens in the GL thread?
I'm not sure if I understood you correctly, but as far as I know Android only shows that report dialog if you use its default UncaughtExceptionHandler.
Try this:
In your UncaughtExceptionHander's constructor, call Thread.getDefaultUncaughtExceptionHandler and save the returned object in a variable (let's call it defaultHandler). In your Handler's uncaughtException() do the things you want to do, and then call defaultHandler.uncaughtException() afterwards.
Maybe something you should know:
In my experience, your Context isn't functional anymore at uncaughtException(). So, you can't send broadcasts, etc anymore.
By the way, if you really wrapped everything in try/catch, that could be the reason why error reporting doesn't work as expected? :P
Good luck
Tom
Perhaps the force closes are caused by stalls, rather than exceptions. Users may not notice the difference. This kind of problem can occur more often if users have CPU hogging services running at the same time as your application, which explains why you're not seeing the issue in your testing.
Permission Internet sounds a lot like you try to transfer data from the net, which is very fast in your local LAN, but all of a sudden becomes slow (and time consuming) when people try this over their GSM connections.
If you then do the data transfer in the UI thread, this one is blocked and the system detects the block - but then this should end up in a "Did not respond" -- but then I've seen one user report an error with in the market on my app that was such a slow down cause.

Categories

Resources