21

I am trying to write a Robolectric test. I was following few tutorials where they seem to be using

@RunWith(RobolectricTestRunner::class)
@Config(constants = BuildConfig::class)

to setup the test, but in my case The parameter constants does not seem to resolve.

enter image description here

My Robolectric dependency looks like this:

testImplementation "org.robolectric:robolectric:4.0.2"
halfer
  • 19,824
  • 17
  • 99
  • 186
erluxman
  • 18,155
  • 20
  • 92
  • 126

2 Answers2

19

constants parameter is now deprecated see the doc :

constants
Deprecated. 
If you are using at least Android Studio 3.0 alpha 5 please migrate to the 
preferred way to configure builds for Gradle with AGP3.0 
http://robolectric.org/getting-started/

The proper way to set up Robolectric per the documentation is :

android {
  testOptions {
    unitTests {
      includeAndroidResources = true
    }
  }
}

dependencies {
  testImplementation 'org.robolectric:robolectric:4.1'
}
Guerneen4
  • 708
  • 8
  • 17
0

Robolectric is for unit test, not for androidTest, so please confirm that your test case is under src/test, NOT under src/androidTest.

shizhen
  • 12,251
  • 9
  • 52
  • 88
  • Yes is inside src/test its my reference Project/app/src/test/java/com/erluxman/productive/MainActivityRoboTest.kt – erluxman Nov 26 '18 at 03:23