0

Referring to https://developer.android.com/training/testing/unit-testing/local-unit-tests.html and https://medium.com/@ali.muzaffar/the-basics-of-unit-and-instrumentation-testing-on-android-7f3790e77bd, I added

testCompile 'junit:junit:4.12'

in my gradle. Then I created a new test class, but apparently

@Test

throws 'Cannot resolve symbol'. On pressing ALT + Enter, Android Studio suggested me to 'Add testng to classpath'.

I don't quite understand what's going on here. I thought I don't need testng for what I'm trying to do here, nor the 2 articles above also didn't mention anything about testng.

Furthermore if I followed the Android Studio suggestion to 'Add testng to classpath', Android Studio will automatically add

androidTestCompile 'org.testng:testng:6.9.6'

in my gradle. And when I try to run the test, I will get the error

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/Description;
imin
  • 4,504
  • 13
  • 56
  • 103

1 Answers1

0

Apparently changing

testCompile 'junit:junit:4.12'

to

androidTestCompile 'junit:junit:4.12'

solves this. Android Studio also won't bug me to add testng to classpath.

This Confused about testCompile and androidTestCompile in Android Gradle also helped me to understand more about testCompile vs androidTestCompile

Community
  • 1
  • 1
imin
  • 4,504
  • 13
  • 56
  • 103