Does Eclipse require a separate android project for unit tests? - android

I'd like to add my AndroidTests to an existing project and run it from eclipse. I do not want to have a separate Eclipse project for the tests.
Is this possible?
When I try, Eclipse complains that uses-library instrumentation is required, which effectively means that an Android project cannot run its instrumentation tests if they are within the same project.
Using gradle, I can place my Android test code within the same project as the source production code, but I cannot do the same with Eclipse.
This leads to a disconnect where there ends up being 2x as many Android projects just to run in Eclipse, when gradle can handle single projects just fine.
Are there any workarounds?

Is this possible?
If the project creates an Android library project, then yes. If the project creates an Android application, then no. An Eclipse project basically creates one APK output, which can either be a test project (perhaps incorporating code from a library) or an application, but not both.

Related

Android - Build application without eclipse

I have one main application and an Android library project that it
uses
I can compile and run the application fine in eclipse
when I try to build the same app using ant I am facing issues
I am not able to get the same result with aapt that eclipse does(in
the background)
eclipse plugin seem to merge the resources together (layouts, icons,
strings, etc) for both the main app and the library project.
Anyone knows how to do this in command line in aapt
Thanks
Check the documentation: http://developer.android.com/tools/building/building-cmdline.html
It has everything about building without Eclipse.
You can compile your applicaiton without eclipse using this way. Its a perfect idea. Also refer this blog.

Error linking a native library from another project to a JUnit Test Project

I have run into some issues while working on Android JUnit Test, the details of which are given below.
I have an Android application (which is to be tested) and a corresponding JUnit Test project (which tests the application). Also, I have another project, which contains some native library which I intend to use in my Test project.
I have tried to use the other project as a library under eclipse but when running the JUnit test, an error comes up stating “findLibrary returned null”.
There is a workaround for this by putting the native library in the application to be tested and then using it. But I don’t want to put the testing library in the application. Is there any solution for this?

Testing my android library without compile

I would like to test my library in an android application, but I would like to avoid compiling and moving around .jar files.
In Xcode for iOs development, it's possible to add your library project in your workspace inside your other project (a test app) and when you run your test app, it builds the library and links everything up correctly.
Can I do this for Android development in Eclipse? How can I do this?
I tried to add a library but it seemed very manual which isn't ideal on time.
The important thing here is that I do have Android references and dependancies, so i can't just unit test the library by itself. I am also creating an SQLite database which I would like to inspect during development.
I guess you are asking about Android Library projects, otherwise you can just test your library using JUnit.
In such case, the post android: testing library projects gives you a step by step guide on how to proceed to test the Android Library project in a stand-alone fashion. Think it can also be tested through the tests belonging to the Android project that uses the library.
You can test your library code using RoboElectric that allows you to test without the need of deploying an android emulator.
Or you can set your library project as an Android library project and put the test in the first project. link
In latest android SDK tools you do not need to add jar in build path, they will be added automatically.
you can put you jar file in libs folder of your project, But it will defiantly be compile before running.

Android Test Project Directory Structure When Using Eclipse

Once upon a time, I avoided Eclipse for Android development. And life was good.
Along the way, I adopted a convention originally supported by the Android command-line build tools, of having a tests/ subdirectory containing the test code (e.g., MyProject/ being the home of the app, MyProject/tests/ being the home of the test suite). Android does an excellent job of allowing test code to reside in a separate-but-related project, and having it as a subdirectory kept the tests logically co-located with the project proper.
I am now switching to Eclipse, as I need to support it better for my subscribers. The only way for me to do a quality job of supporting it is to use it daily. And, since I have a quad-core with 4GB of RAM, Eclipse actually starts up in less than a minute. :-)
However, preliminary research suggests that Eclipse does not support sub-projects (i.e., one Eclipse project having another Eclipse project in a subdirectory).
So, my questions are:
Am I correct in this assessment, and if I'm wrong, are there any particular steps I should take to ensure that Eclipse is happy? I find that Eclipse can sometimes get a wee bit cranky...
How are Android developers organizing test projects relative to the project being tested? Peer directories (e.g., MyProject/ for the app, MyProjectTests/ for the tests)? Peer subdirectories under some targeted common top (e.g., MyProject/app/ for the Android app, MyProject/tests/ for the test suite?)? Something else?
BTW, I'm running Eclipse 3.5.2, if that matters.
Thanks!
I've been creating test projects with Eclipse 3.6.2 inside my main project just like you describe for command line tools (MyProject and MyProject/test are Android projects that both contain a src folder). You can create this test project using the New Android Test Project by deselecting "Default Location" and setting the path.
None of my projects are very large, but the only problem I've had so far is that you cannot use the MyProject/test folder under the MyProject project. To be able to right click and run as a test case, you have to access files directly from the MyProjectTest project. To prevent you from having problems, you can add a Resource Filter to hide the test folder in Project Properties > Resource > Resource Filters.
However, preliminary research suggests that Eclipse does not support sub-projects (i.e., one Eclipse project having another Eclipse project in a subdirectory).
What problems have you seen?
Depends on your toolset:
ADT >= v12 currently has flaky support for "a project within a project":
Creating an Android Test project in Eclipse
I have tried separate testproject, and separate test directory, but afaik "a project within a project" approach seems to be the way of the future.
This is becuase AndroidManifest.xml merging into the test project AndroidManifest.xml, is in the pipeline for the next ADT releases.

Set up Android testing in Intellij IDEA

Have someone got any tutorials for how to do testing on Android in Intellij? I am looking for resources similar to what you find for Eclipse with the ability to create a test project for my android project.
You can find some help in the IDEA forum thread.
Tests for Android application should be located in a separate module with its
own AndroidManifest.xml file. To find out how to create tests for your
Android application, you can use samples in Android SDK (i.e. "Snake"
sample).
Create IDEA project from existing sources. 2 modules with
Android facets will be created automatically: base module and "tests". Then
add dependency between these module and compile. If compilation is
successful, open some test class (i.e. "SkeletonAppTest" in "Snake" sample)
in editor and select Run->SkeletonAppTest (with Android icon) in the popup
menu: tests will run on emulator or device. You can create Android
Tests run configuration to run tests in different scopes.
Unfortunately, IDEA 9 doesn't have an option to create test module for some
base Android module. You can create it using SDK command-line tool.
Here's the general Android/Eclipse info:
Android testing overview:
http://developer.android.com/guide/topics/testing/index.html
Testing practicalities for Eclipse and command line:
http://developer.android.com/guide/developing/testing/index.html
Tutorial:
http://developer.android.com/resources/tutorials/testing/helloandroid_test.html
and to create a test project in IntelliJ:
http://blogs.jetbrains.com/idea/2010/09/android-unit-testing-support/

Categories

Resources