noobler
noobler

Reputation: 3805

Android unit testing - how to run tests in same project as application?

In the Android LunarLander sample project, the unit tests are included right in the project, in a (non-source) folder called 'tests'. This is in line with the SDK testing guide which recommends this layout as opposed to creating tests in a separate project. However, I have no idea how I can actually run these tests.

I can't create an Android Junit Test run configuration:

It's starting to seem to me that this sample is broken... I hope I am wrong, since I'd rather embed tests into my project and be able to run them easily (instead of creating a separate test project that links to project for application under test). Does anybody know how I can run these tests? Thanks...

Upvotes: 2

Views: 1326

Answers (1)

yorkw
yorkw

Reputation: 41126

Google recommend a single all-in-one directory because it makes your files easy maintainable in many situation, for instance when dealing with source control.

It doesn't matter where the test project is located int the file system, however, you must import it into your Eclipse's workspace, same as what you did for the LunarLander project:

enter image description here

If everything goes well, your Package Explorer should look something like this:

enter image description here

In my Android 4.2 samples, things are not going well, it seems that the source code of LunarLander test project is not up-to-date:

  1. it doesn't come with project.properties file.
  2. it uses same package name as LunarLander project, resulting Eclipse to be fooled when importing package/class from the referenced LunarLander project.
  3. it doesn't automatically add the LunarLander project to test project's classpath, resulting imported package/class from the referenced LunarLander project is invisible.

Once you resolve all issues, you should able to run/debug Android JUnit Test from test project.

Upvotes: 1

Related Questions