robospock / RoboSpock

A testing framework which brings powers of Spock and Groovy to Android app testing
http://robospock.org
MIT License
249 stars 44 forks source link

Specification only read @Config annotation on its own, not including parent class #56

Closed allenz8512 closed 8 years ago

allenz8512 commented 8 years ago

Usually I would use a base test class to carry all setups and cleanups, like:

@Config(sdk = 21, constants = BuildConfig, manifest = "app/src/main/AndroidManifest.xml", application = App.class)
class BaseRobolectricSpec extends GradleRoboSpecification {
    def app = (App) RuntimeEnvironment.application;
}

But it throws "No 'constants' field in @Config annotation!" exception when I put @Config on the base test class insteads of specify specification, so I should copy the same @Config annotation everywhere.

pjakubczyk commented 8 years ago

Annotation doesn't go well with inheritance. The best option is to add a configuration file to your project. Place it there: src/test/resources/robolectric.properties

for example my properties file looks like this:

constants=com.applause.android.BuildConfig
sdk=21

When you extend from GradleRoboSpecification you don't need to place sdk, manifest etc values. The BuildConfig (generated file) holds all necessary data to run tests

allenz8512 commented 8 years ago

Thank you for advise.My problem is solved.

pjakubczyk commented 8 years ago

:)