Create android unit test for and
2017-11-24 本文已影响4人
JaedenKil
- Locate the
class
you wish to test, pressShift + Ctrl + T
. - In the newly shown menu, choose
Create New Test
. - In
Test library
, chooseJUnit 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 asapp\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.