????3?????????????????“????????”build.gradle????У????????????????????
????· Android Studio???????????е???????????????

????· ????????????“sourceSets”???????????????????????????????(????Eclipse?AS??????????)
sourceSets{
sourceSets{
main{
java.srcDirs = ['src']
}
androidTest{
java.srcDirs = ['androidTest/src']
}
test{
java.srcDirs = ['test/src']
}
}
????????????????????????
????androidTest  “Android??Junit”
????test “java????????”
????????
junit
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
System.out.println("123");
}
}
Android junit
public class AndroidRuntimeCodeTest extends AndroidTestCase {
public void testHello() throws Exception {
System.out.println("testHello");
}
}
????????
????1?????????
???????Eclipse????????????AndroidManifest.xml????
<manifest >
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.viewtest" />
</manifest>
<application>
<uses-library android:name="android.test.runner" />
</application>
????Android studio???build.gradle
??????????????
??????
????android{
????defaultConfig {
????testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
????}
????}
????2???????????“??????????????”??????“?????????”?????????
?????????https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
????https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Resolving-conflicts-between-main-and-test-APK
????configurations.all {
????resolutionStrategy {
????androidTestCompile 'com.android.support.test:runner:0.4.1'
????androidTestCompile 'com.android.support.test:rules:0.4.1'
????forcedModules = ['com.android.support:support-annotations:23.0.1']
????}
????}