Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Config constants parameter could not be found in Robolectric

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"
like image 842
erluxman Avatar asked Nov 26 '18 03:11

erluxman


1 Answers

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'
}
like image 60
Guerneen4 Avatar answered Sep 19 '22 15:09

Guerneen4