Dependencies can be added for specific configuration like test/androidTest
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
testCompile 'junit:junit:3.8.1'
Alternatively create your own configuration
configurations {
myconfig
}
And then download dependency for this config
myconfig group: 'com.mycompany', name: 'my_artifact', version: '1.0.0'