@Overridepublic InstrumentationConfiguration createClassLoaderConfig() {
InstrumentationConfiguration.Builder builder = InstrumentationConfiguration.newBuilder();
builder.addInstrumentedPackage("com.example.yourClassToShadowPackage");
return builder.build();
}
@Implements(ClassToShadow.class)
public class MyShadowClass {
@Implementation
public void myShadowMethod() {}
}
Make sure that the package hierarchy does not contain the classes which you are testing in your unit tests. Otherwise test cases will fail.
I am working on a more elegant way to do.
--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ShadowExtrator
@RealObject
private MyClassToShadow realMyClassToShadow;
@Implementation
public void setTestMember(String value) {
realMyClassToShadow.setTestMember(value + testPrefix);
}
This leads me in a StackOverflowError
at com.citrix.robolectricshadow.MyClassToShadow.setTestMember(MyClassToShadow.java)
at com.citrix.robolectricshadow.shadows.MyShadowClassToShadow.setTestMember(MyShadowClassToShadow.java:20)
public class ShadowRobolectricGradleTestRunner extends RobolectricGradleTestRunner{
/**
* The list of the customized shadows classes name.
* Note they should be full qualified.
*/
private static final String[] CUSTOMIZED_SHADOWS_NAME = {
DataManager.class.getName()
};
public ShadowRobolectricGradleTestRunner(Class<?> klass) throws InitializationError {
super(klass);
}
@Override
public InstrumentationConfiguration createClassLoaderConfig() {
InstrumentationConfiguration.Builder builder = InstrumentationConfiguration.newBuilder();
for(String packageName : CUSTOMIZED_SHADOWS_NAME){
builder.addInstrumentedClass(packageName);
}
return builder.build();
}
}
@Implements(DataManager.class)
public class ShadowDataManager {private Context context;public void __constructor__(Context context) {
this.context = context;
}@Implementationpublic String getCustomers() {return "shadowCustomers";
}}