Sundeep Khandpur
unread,Sep 29, 2011, 3:34:18 PM9/29/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Android Mock Discussion, rob...@google.com, iv...@google.com
Hi,
I am using the flag regenerateframemocks=true and it generates the
mocks with UNKNOWN sdk version (i.e. "" as the prefix of the head
directory) but when I run the tests, it looks for v233...I looked at
the code and basically it does the following:
For generating the mocks, it calls:
createMocksForClass(clazz, SdkVersion.UNKNOWN);
for loading the mocks during runtime, it checks calls getInterfaceFor:
private static <T> Class<T> getInterfaceFor(Class<T> clazz) {
try {
String className;
if (isAndroidClass(clazz)) {
className = FileUtils.getInterfaceNameFor(clazz,
SdkVersion.getCurrentVersion());
} else {
className = FileUtils.getInterfaceNameFor(clazz,
SdkVersion.UNKNOWN);
}
return (Class<T>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not find mock for " +
clazz.getName()
+ " -- Make sure to run the MockGenerator.jar on your test
jar, and to "
+ "build the Android test APK using the modified jar created
by MockGenerator", e);
}
}
static boolean isAndroidClass(Class<?> clazz) {
String packageName = clazz.getPackage().getName();
return packageName.startsWith("android.") ||
packageName.startsWith("dalvik.")
|| packageName.startsWith("java.") ||
packageName.startsWith("javax.")
|| packageName.startsWith("org.xml.sax") ||
packageName.startsWith("org.xmlpull.v1")
|| packageName.startsWith("org.w3c.dom") ||
packageName.startsWith("org.apache.http")
|| packageName.startsWith("junit.");
}
------------------
Since the isAndroidClass return true, it checks for the mocks under
v233....which does not exist.
What is the best thing I can do if I do not want to include
android_framework_mocks.jar.
Some alternatives/workaround I considered:
a) Make changes to the code of AndroidMockGenerator/AndroidMockRuntime
to be consistent with the generation and loading SDK Versions
b) Before dexing, create a folder v233 and put genmocks folder inside
it, so the proper version name is present.
Any ideas what else can be done?