I'm following this tutorial.
What I want to do is to create unit tests with AndroidJunitRunner
.
My directory in app/src
looks like this:
androidTest
debug
main
release
android docs suggests that I create a test/java
for my unit tests.
The problem is that in android studio I can't create a new directory if I'm on android project mode. And I should find the directory manually and create it manually.
Is there a way to automatically create these directories and tests for one flavor?
I've read this question, which doesn't relate to my problem.
Just change to Project Mode and create the test folder. Take a look to the screenshot.
By the way, I think when you create a project the folder is already created.
It's easiest to just create the folder manually in the directory. Android Studio will notice it pretty quickly and it will show up in your
Android
view.You will need to create the packages in the
test/java
folder too. So if your package name iscom.foo.bar
you need to create the following dir structure in yourapp/src
folder:test/java/com/foo/bar
As an aside in the latest versions of Android Studio you don't need to use
AndroidJunitRunner
anymore. Studio supports JUnit4 tests out of the box.To make tests for a particular flavor you need to append the flavor name to the end of the test folder. So if your flavor is
dev
then the folder structure would be:testDev/java/com/foo/bar