I am currently developing an android app in eclipse using:
One project for the app
One project for the tests (Instrumentation and Pojo tests)
In the test project, I am importing the mockito library for standard POJO testing.
However, when I import the library, the compilation time skyrockets from 1 second to about 30 seconds in eclipse. The cause seems to be that the whole library is converted each time. So basically, each time a make a modification that I want to test, I have to wait 30 seconds.
The only workarounds that I have found so far would be:
Disable "Build Automatically"
Create a project that includes only pojo tests and put mockito only there.
Use another library that compiles faster (e.g. easymock)
Any other suggestion?
Do you need the test project to be an android project?
If can get aware with creating a Java project and mocking out any of the android specific classes for the tests that would be my suggestion.
Have a look at this article:
https://sites.google.com/site/androiddevtesting/
Related
(Sequel to this.) There's a Java library to which I have added patches for Android support. I would like to automate testing of the code, but in order to check if it runs properly on Android, I need to test it on Android. (Current progress here.) I've moved the main code into a "java" module, and created an "android" module to run the Android instrumented tests (tests that run on a device or emulator). Now, I'd really prefer to run all the normal tests again but on Android (so nobody has to rewrite all the tests and keep them up-to-date), by e.g. adding a line to the gradle file or creating a symbolic link, but so far I haven't found a gradle command to do it, and a symbolic link did nothing that I could see. Part of the problem, I think, is that the tests are in Scala. Is there a way to run Scala tests as instrumented tests on Android? (Or another way of equivalently solving the problem without a ton of recurring work?) The easiest probably-doable way that's occurred to me is to add a test in Android that manually calls the other tests (e.g. com.whatever.Tests.testThatThing();), but that requires maintenance as tests are created/removed, and I'm not sure there won't be problems with like, tests not being exported for external use or something.
I'm looking for a way to do a Unit tests on an existing project (java project).
I read the legacy code book. It advance to do some refactoring method, because the Unit tests on an existing project are consuming.
Honestly speaking, the project is big one. I found a question in stackoverflow :
Unit Test existing UI code
I'm trying to find the best solution from it.
Another way that I found it, is on Intellij IDE, we can add a plugin JUnit5 https://blog.jetbrains.com/idea/2016/08/using-junit-5-in-intellij-idea/
We create a test case on each package or module. I started creating the unit test classes, I found a lot of errors, warnings, deprecated frameworks. But, it's consuming a lot.
I'm looking again for a solution. In the meanwhile, please can some one suggest a solution, idea to automate unit tests on an existing java project ?
Thanks in advance.
I have a question about technology or methodology out there that I can use to test my code fast & simply. Recently I came across the difficulty & frustration regarding to testing my code when I was working on an android project. Everytime when i wanted to test my code, i had to re-compile whole project again and wait for emulator to re-install application which at least takes 40~50 seconds just to check a bit of code working fine. Are there any way that I can compile or test just a small portion of code / 1 ~ 2 methods working without having to re-compile whole project every time? Also which one is the latest and most widely used among the industries?
=====================================
Additional question. I've done some research on JUnit testing of java but is JUnit what i'm looking for? or is it different kind of testing technology
you can make a search about Robotium. it provides you to do blackbox testing.
http://testdroid.com/tech/54/automated-ui-testing-android-applications-robotium
Maybe Robolectric is what You are looking for. You can use JUnit to test only java code that doesn't use methods from android sdk.
have you considered using AndroidTestCase? JUnit can only be used to non-android specific function, but this does the job for your Android-specific code.
There is a very detailed account for android testing available at:
http://developer.android.com/tools/testing/testing_android.html
This includes basic as well as activity testing and is built on top of JUnit.
For people that don't want to use Roboticum and such, but just stick with Eclipse built-in JUnit testing, this is what I would recommend:
Have three projects:
AndroidProject
AndroidProject.test
AndroidProject.test.android
In your AndroidProject.test project you only test Models, Controllers and such which exclusively uses Java-libraries. So no Android Logcats, Toasts, or things like Patterns.WEB_URL.matcher(url).matches()) [android.util.Patterns] (which validates a String URL).
In your AndroidProject.test.android project you test the Activities, Services, Model-classes that use Android libraries like the Pattern-validation mentioned above, etc.
To be able to use Eclipse Run As -> JUnit Test for your JUnit test project you have to do some set-up however, like removing the Android API from each individual Test class, using the junit.framework.Assert and org.junit.Test imports, etc. For a full step-by-step guide to reproduce what I have done to make it work, I refer to my own Stackoverflow-post that I've made:
JUnit Test Android classes without being forced to start the (slow) Emulator.
How can I execute a block of code in an android project without having to launch the emulator.
I don't want to deal with the android lifcycle -> I want to test the logic of my app ONLY.
What I have in mind is to create another java project and define dependencies so that I can access the classes that are in my android project.
I would like to launch a kind of Main() method to bypass the emulator... Is it possible?
Thanks!
Look into unit testing. Fits your problem almost perfectly.
Not exactly for a block of code but for methods.
There are special launchers such as JUnit that makes the test-running smother and much more fun. You get green and red lights for every test, great satisfaction to get all green.
JUnit is fairly easy to get started with and is well integrated into eclipse.
I'm trying to develop an external library (not sure if that's the right term) to provide prepackaged functionality in Android projects. Working in Eclipse, I've added the appropriate android.jar file to the build path, and everything is happy both while editing and upon compilation.
However, when I use Android's Handler and Message classes (android.os.Handler, android.os.Message) for inter-thread communication, I get exceptions unless I'm running within an Android app, on the emulator or a device. I can no longer test my library in a "standalone" way without having to go through a running Android target.
Is there any way for me to include these two Android classes and still be able to test my library standalone? Do I need to have the Android source available? Or would it require some sort of conditional compilation hand-waving?
Is there any way for me to include
these two Android classes and still be
able to test my library standalone?
Not readily, by any means I can think of.
Do I need to have the Android source
available?
I don't know where else you would get the implementation from. But, more importantly, those things are not designed to work in isolation outside of the OS, any more than you could just grab a Cocoa class or two and pull them into your Objective-C library and expect them to run on a Windows box.
Off the cuff, knowing nothing about what you're building, I would make whatever dependency you are introducing on Handler and Message be more pluggable. Test outside of Android using a pure-Java implementation, perhaps even just some mocks. Test inside of Android using the real implementation.
You could try the lib Robolectric, that implements the android API so you would be able to create JUnit tests for some isolated code you have:
http://robolectric.org/