- Locate the
class
you wish to test, press Shift + Ctrl + T
.
- In the newly shown menu, choose
Create New Test
.
- In
Test library
, choose JUnit 4
.
- Name the
Class name
.
- Press
OK
.
- Choose destination directory, such as
app\src\androidTest\...
.
- Press
OK
.
- Remove possible unnecessary newly generated directories.
- In
app level build.gradle
, such as app\build.gradle
, add necessary dependencies. Such as:
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-annotations:23.1.1'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
- Solve possible dependency conflicts.
- In the newly created java test file,
Alt + Insert
to generate new method automatically.
网友评论