Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why to hold tests in a separate project rather then folder?

Just out of interest - why has it been decided to move tests to a separate project, not just to a separate source folder?

like image 278
Eugene Avatar asked Jan 16 '11 19:01

Eugene


2 Answers

The test application "instruments" the target or main application.

The instrumentation section in the test project's AndroidManifest.xml allows the tests to run in the same process as the application. This instrumentation feature allows the test application to step through android component lifecycles in a controlled way.

Having this control allows you to (for example) create repeatable tests for cases for the activity lifecycle (create,resume,pause,destroy).

see http://developer.android.com/guide/topics/testing/testing_android.html#Instrumentation

So in summary, the extra application has special powers over the test target. Since these are encapsulated in the test application, your real application need only have the permissions it requires to perform its duty.

like image 137
byeo Avatar answered Oct 18 '22 08:10

byeo


The current documentation, as I interpret it, states that you should hold the test code in a separate project in folder "tests" inside the applicaton project => "A project within a project"
http://developer.android.com/guide/topics/testing/testing_android.html#TestProjects

How ?
Creating an Android Test project in Eclipse

Why ?
Instead of ex. 40 projects you have 20 projects => better overview, less maintenance, faster eclipse.
Two build.xml => easier CI builds with Jenkins
Two manifest files => future versions of ADT build tools will support manifest merging

like image 44
user77115 Avatar answered Oct 18 '22 09:10

user77115