Reputation: 587
i think tests in the instruementTest should relevant to android, so need i add an addtional source folder such as src/test/java? it looking that the testfile in src/test/java didn't compiled.
how can i run a junit test independently?
how can i run the junit test only in a command line, no the instrumentTest about android?
or put and junit test in the instruementTest folder and call
./gradlew connectedInstrumentTest
but,the unit test won't run at all.
Upvotes: 7
Views: 5004
Reputation: 24464
Right click on the test file in the Project view. Choose Run ...
Don't forget, the directories structures for tests and tested classes must fit. Yours seem dubiously. Here is how to do it easily.
Upvotes: 0
Reputation: 366
First, You should built appropriate folder structure in order to match default structure that Gradle is expecting. In Your gradle.build inside android{} section You should add:
sourceSets {
instrumentTest.setRoot('src/instrumentTest')
}
then You should create appropriate folder structure in your src/ folder. Now You should have main/java/your/package/name/YourActivity.java . In order for Gradle to find Your tests You should create structure in src/ folder to mirror Your main structure, like: instrumentTest/java/your/package/name/YourActivityTest.java
next, for Gradle to compile your dependencies You should add in Your gradle.build:
dependencies {
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.2'
instrumentTestCompile 'junit:junit:4.10'
}
Remember, that those are dependencies outside Your buildscript{} section. After You apply those changes You should be able to run Your JUnit tests as well as Robotium tests. Do not forget to hit the 'make' button couple of times for Gradle to catch up.
Upvotes: 0
Reputation: 5228
I think this is not possible if you only have the Android plugin in your build.gradle. The only testing that is supported in the Android plugin is in the InstrumentTest folder. The normal test folder is only used by other plugins.
Next to that there is probably support needed in Android Studio itself. But not sure about that.
Upvotes: 2