Just downloaded Android Studio which is based off of the Intellij Idea.
How would one create tests?
I notice there is a option for create a Test Module but this doesn't seem to do anything, only create a new project with src
I also tried pressing the hot key CTRL+AlT+T which allows to create unit tests on an existing class but it seems to want to place it in the current project. Of course this doesn't help with TDD
Does anyone have any experience here ?
As of now (studio 0.61) maintaining proper project structure is enough. No need to create separate test project as in eclipse (see below).
I think this post by Rex St John is very useful for unit testing with android studio.
http://rexstjohn.com/wp-content/uploads/2014/01/Screen-Shot-2014-01-24-at-6.26.20-PM-300x137.png
Android Studio keeps evolving so the responses above will eventually be no longer applicable. For the current version of Android Studio 1.2.1.1, there's a nice tutorial on testing at:
http://evgenii.com/blog/testing-activity-in-android-studio-tutorial-part-1/
Add below lib inside gradle file
Create class HomeActivityTest inside androidTest directory and before running the test add flurry_api_key and sender_id string inside string resource file and change the value for failure and success case.
Edit: As of 0.1.8 this is now supported in the IDE. Please follow the instructions in there, instead of using the instructions below.
Following the Android Gradle Plugin User Guide I was able to get tests working on the command line by performing the following steps on a newly created project (I used the default 'com.example.myapplication' package):
This ran my tests and placed the test results in MyApplicationProject/MyApplication/build/reports/instrumentTests/connected. I'm new to testing Android apps, but it seem to work fine.
From within the IDE, it's possible to try and run the same test class. You'll need to
However this fails (the classpath used when running the tests is missing the test output directory). However, I'm not sure that this would work regardless as it's my understanding that an Android specific test runner is required.
Android Studio v.2.3.3
Highlight the code context you want to test, and use the hotkey:
CTRL
+SHIFT
+T
Use the dialog interface to complete your setup.
The testing framework is supposed to mirror your project package layout for best results, but you can manually create custom tests, provided you have the correct directory and build settings.