??Android Studio???С??????á????????
?????3H ???????[ 2016/7/21 14:11:41 ] ????????Android Studio ???????
????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']
????}
????}
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11