Testing my maven library compatibility with Android - java

TL;DR
I have a Java project that I build and test with maven. What it the simplest way to run my junit tests on an Android sdk?
More details
After a commit, a user open a bug report to explain that I broke the compatibility with android since I introduced a dependency on javax.xml.bind and this package doesn't exist on Android.
Now I managed to implement my feature without using this package, and I'd like to be sure I don't break this compatibility anymore. Consequently I'd like to run my existing junit4 tests on the Android Sdk. The issue is that I'm an Android noob, and I'm starting to drown under documentations:
would using local unit tests fit my needs?
If yes, may I use them with maven or shall I switch to gradle first? (ie: the documentation explains how to do it using Gradle. Is it a prerequisite, or is it possible to do it with my existing build system?)
Or must I go through the burden of using instrumented unit tests? (Are those even usable given that there's no notion of UI at all in my project?)

Yes. Android Plug-in for Gradle keeps track, that you're not using APIs your are not allow to use due to API level minSdkVersion limitations of the lib. (I'm pretty sure, it also archivable with maven-android-plugin)
It's possible and requires Surefire Plugin. I haven't try it personally, unfortunately, so I can just say that from what I briefly read - it looks ancient and not particularly easy to set up. So if I were you, I'd go for Gradle. But if costs of it is too high - well. It's doable with maven too.
Unless you want to test activities and some complicated end-to-end UI(fragments, intents, etc.) scenarios - you're good to use JUnit tests. And even if you do need something Android's Activity/Fragment-related, you can use Robolectric lib for it (it's a unit test framework, allows to avoid instrumented tests in many cases)

Related

Integrating Selenium Test Suite (Eclipse) with TFS

I've been asked a question by one of our developers here. They are asking whether it is possible for a selenium test suite to be tied in with a TFS build in visual studio to the test server? So that way, as soon as a build is done it can kick off a run of the regression test suite, directly after that.
Bear in mind that my scripts have been written in Eclipse, NOT Visual Studio, so I'm not sure if this will cause restrictions.
You can call UI scripts as you describe and I would additionaly recommend that you use Release Management to do this rather than build. It makes much more sense to use a deployment engine rather than a compilation engine to maintain this. One does not usually have an instance of ones application running on the build server.
http://nakedalm.com/execute-tests-release-management-visual-studio-2013/
You need to get a few things lined up, but it worked pretty good..

Is it possible to mix JUnit3 and JUnit4?

I believe that you can help me solve problem connected with compabitility JUnit libraries.
The problem is that we develop mobile apps (android) and we're using test managment tool called SpiraTest. We want that unit test results will be exported to SpiraTest automatically so want use junit extension for Spiratest (made by Spira team). Problem is that it requires JUnit4 to integrate, what Android doesn't support.
What would you recommend to do?
I would say that if you are going to do unit testing of you own functionality it won't really matter if Android supports it or not, you just run the unit tests regardless of the Android SDK. However if you intent to use jUnit to work alongside Android, there is no way at the moment to do it that I'm aware of.

Unit testing non-Android specific code in an Android app without emulator

Android newbie here, using ADT
I have a few number crunching classes in my app that are "pure" Java - they don't depend on anything in the Android SDK. Ideally, I'd like to test them without firing off the (somewhat slow) emulator. Is that possible and if yes, how?
From what I gather so far, Dalvik compilation and resulting classes are different than the ones expected from "normal" JVMs and that rules out regular JUnit tests (what happens if you try). Using the JUnit in the Android SDK starts the emulator. Here's where my Google fu fails me for everyone is preoccupied testing UI.
Is that possible and if yes, how?
Option #1: Follow Mike B's comment and move that code to a separate JAR project with its own unit tests.
Option #2: Use Robolectric to run dedicated tests for these classes on the JVM. While Robolectric is mostly designed to test Android-y code on the JVM, I see no reason why you could not use it for your scenario as well.

How to incorporate an Android Application Project onto a Java Project - Eclipse

I am a beginner with Java and Eclipse. I am trying to create an automated framework with both Selenium (Web application) and Robotium (Android Application). I have both project completed, one is a Java Project (Selenium) that uses the JDK compiler to run Junit test cases, and the other one is an Android Test Project that uses the Android Compiler to run android test cases.
My questions is: is there a way to combine an Android project onto a Java project?
I have tried adding the essential files/changes of an android project onto the java project but when I run each test it fails because it uses different compilers.
Is there a way around this? I am open to any suggestions.
Thank you in advanced!
After reading your comment I believe i can say that you should keep them separate. If you want to share some functionality between them all (I cannot imagine you could share all that much between all 3, between android and selenium maybe as they are at least in the same language) then you can create another project and use this as a shared source folder between the two. You will find having them separate makes a lot more sense. The most glaring example is with version controlling your tests, you will find you will want to make tags when you release the actual application, with a single project you will be tagging your individual project for any release of any of the three applications when they will not reflect the actual state of release. That hopefully makes sense. I am pretty tired.

Suggest a good Android development workflow

I'm interested in developing android applications. I've a background of Java/Swing/C++/ajax developer so I think I may find myself at home. As I installed the SDK I noticed that I can't follow my usual java development scheme: building base libraries, then the final app. In fact I'd like to develop libs and test them in a more convenient environment like, Swing. There is no way I can use android libs in pure swing apps...
Do you have any suggestion about these topics and what's your development process?
If you have written a lib that does call functions from the android jar, you can write JUnit 4 tests in a separate Project and execute them to test your lib functions. This forces you to keep some of your functionality separated from the android specific things and you can then be sure that all the errors you tested for are gone before you introduce the problems that can arise if you are running on the device. You can do JUnit Tests on the emulator too but that is a little bit more complex.

Categories