Android unit Test are passing on MAC but failing on windows - android

I have written the unit test cases which include access to shared preferences and encrypted shared preferences. The tests are running and passing on MAC machine. However tests are failing on windows with the exception below.
java.io.IOException: Unable to rename
C:\Users<UserName>\AppData\Local\Temp\robolectric-Method_testFunction\com.example.application-dataDir\files\datastore\test_preferences.preferences_pb.tmp.This
likely means that there are multiple instances of DataStore for this
file. Ensure that you are only creating a single instance of datastore
for this file.
I searched a lot some people say that this is a windows issue, some say this is roboelectric issue and some say we should write instrumentation test for data store. please suggest me what should I do.

After spending lot of time and tried so many solutions I finally found the solution. Updating the data store version from 1.0.0 to 1.1.0-dev01 worked for me. I am able to run the test cases on windows also.

Related

How can I launch Android Studio tests with a batch file?

So I have an Android project for which I created a test. But I'd like to run this test multiple times in series. So I thought that it is perhaps possible to run a test scenario from the command line and write it into a .bat file. But I can't really find any solutions that I can understand. (I'm quite new to Android Studio.)
So is it possible and if so, how?
You can use the ANT jars ant.jar and ant-launcher.jar
Please go through the documentation here

Android Build Server for a 1 Programmer "Team"?

Would you recommend the overhead of installing & configuring an Android build server for a 1 programmer project?
The alternative is to upload all sources from development computer to git, download to another computer with Android Studio & Android SDK, and build from Android Studio.
If the answer is yes, would you recommend Jenkins, or another solution?
IMHO, yes, if you have significant time to set it up and maintain it on a separate machine. (I personally would not use a shared machine: too many reasons to restart and disrupt it.)
I feel an extra level of confidence each time I check in if Jenkins builds the whole project successfully from a fresh dir (one less thing I have to do.)
If I forget to check in an important file, Jenkins complains. Or, if I code something that generates a new Lint warning, Jenkins puts a spike in the graph. In other words, on solo projects, Jenkins is like an assistant (or mentor) that helps check my work.
Jenkins can warehouse app installers for future reference. So, it also helps me stay organized.
Jenkins offers some nice communications capabilities too. You can have it automatically notify others via Slack, or put an installer on Dropbox, or, through a service like Zapier, create a custom card in Trello. So Jenkins gives me an outward-facing messenger and delivery service.
These are some plugins I have found useful with Android builds:
Android Lint
Credentials Binding
Environment Injector
Gradle
Slack Notification
ThinBackup
Version Number
Zentimestamp
Of course, this only scratches the surface.
It requires some ongoing maintenance work though. And sometimes it's confusing/challenging to configure. (e.g. some plugins are poorly documented or no longer actively maintained. The linter in Android Studio is not exactly the same as the default one run through gradle by Jenkins, etc)
When I first set my build server up, I had a couple weeks of downtime when I was able to experiment with different plugins and troubleshoot the server. I probably wouldn't have done it without that empty window of time at the start.

How can deploy automated test program in Android

I need to deploy my automated test program and ensure manual test team can use it.My solution is write a desktop UI program and install apk,switch language,switch versions,select test cases.Then i can make my test program easy to use anyone who doesnt know code.But if i do this , it takes long time.
Is there anyone have similar experience or provide easier solutions, frameworks to me?
If you need an apk with Robotium tests inside use Gradle tasks like connectedDebugAndroidTest.
To create just an apk file use assembleDebug. Generated '.apk's you would find in this directory: {app-name}/app/build/outputs/apk.
Read also about Continuous Integration and its tools like Jenkinsor Travis(which is free for open-source project on GitHub) to make generating .apk files more automated.
Hope I answer your question. If no, please free to describe what I missed.

Deploy/test without packaging

Is there some way to get the android SDK build process to do partial updates on the actual device? Whenever I make a change it has to rebuild the apk file and deploy it, which seems wasteful, and is slow (especially with the dex defect).
The copying to the device isn't an issue here, it is fast enough. So the emulator doesn't appear to solve my problem. Is there perhaps a way to test the code without producing the APK file for the emulator?
What you want is Test Driven Development (TDD). This article will start you off right :
http://pivotal.github.com/robolectric/
Is there some way to get the android SDK build process to do partial updates on the actual device?
Not presently. It's something they are considering for a future overhaul of the build system, though I think there are other capabilities that are considered to be higher priority..
Is there perhaps a way to test the code without producing the APK file for the emulator?
Not with standard Java-based Android development. Any sort of compiled environment pretty much needs the code to be compiled in order for it to be run.

Can Android use standard built JAR files?

Im pretty sure the answer is no, but im using the new IntelliJ EAP version and have a project i worked on a while back which was just written against JDK 1.6 for an applet based application.
However now i could see how it could be useful in an android app that im interested in creating.
Do i now have to re-write all the code/tests again targeting the android sdk or can i just drop in my existing JAR file and only use android for the UI layer.
Its just android seems to make testing WAY harder than it needs to be, and i have alot of existing tests written and working, if it wasnt so hard to just write a quick unit test (standard Junit #Test style) i wouldnt mind porting, however i just dont get the whole instrumentation thing, as i dont need a UI at the moment...
Anyway so back to the point, can i use my existing JDK built code in an android app?
No!
Android uses the "Dalvik" VM from project harmony which uses a different set of bytecodes which are incompatable with the standard Java JVM bytecodes.
This was done both to optimise the VM for opreration on mobile platforms, and, probably more importantly to try and avoid Copyright and patent disputes with Sun and now Oracle.
More info here
However there is a tool called "dx" which can perform the conversion in the dev environment.
Okay, let me clear up your confusion.
Jars are converted to dex Dalvik bytecode during the compiling process thus you can use 3rd party jar libs.
However, in your case because its applet which has a different application lifecycle yes you might have to re-do it to get it to work in android.
As far as testing instrumentation is used on all java mobile development even JavaMe. It basically means that the Junit tests are run in the emulator or device but in android's case you are using android mock objects to test android specific things.

Categories

Resources