问题
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.
回答1:
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 is com.foo.bar
you need to create the following dir structure in your app/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
回答2:
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.
来源:https://stackoverflow.com/questions/37762095/create-unit-tests-in-android-studio