9

The answer to AndroidJUnit4 and Parameterized tests links to a Google example for using @RunWith(Parameterized.class). However, this is a simple unit test. How do I run parameterized instrumented tests?

Community
  • 1
  • 1
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268

1 Answers1

-2

Actually, you should put your test with @RunWith(Parameterized.class) runner in the androidTest folder instead of test folder. That test will be run on the emulator and you will be able to unit test classes with android dependencies, like android.graphics.Rect etc. Of course, don't forget

defaultConfig {
    ...
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

and dependencies :

dependencies {
    androidTestCompile 'com.android.support.test:runner:+'
    androidTestCompile 'com.android.support:support-annotations:+'
}
Beloo
  • 9,723
  • 7
  • 40
  • 71
  • So I just use a ActivityRule and still get full instrumentation? Even without AndroidJUnit4? – Code-Apprentice Oct 06 '16 at 15:14
  • @Code-Apprentice. Yes. By the way, you don't need runner annotation at all if you have set testInstrumentationRunner in gradle. You can just try to make sure – Beloo Oct 07 '16 at 07:27
  • Even though this question old, it is still relevant to an ongoing project of mine. I will give this a try when I can and give you an accept and up vote after I confirm. Don't hold your breathe, though. Also thanks for the extra info regarding test runners. – Code-Apprentice Oct 07 '16 at 15:30