2

I want to write some unit tests and instrumentation tests for my android project.

However, I've met a problem that stuck me a while... I need to mock a static method and fake the return value to test the project.

After survey from some forums, the only way to do this is to use PowerMock to mock the static method.

This is a part of my gradle:

androidTestCompile "org.powermock:powermock-module-junit4:1.7.0"
androidTestCompile "org.powermock:powermock-module-junit4-rule:1.7.0"
androidTestCompile "org.powermock:powermock-api-mockito:1.7.0"

and my test class:

@RunWith(PowerMockRunner.class)
public class MyClassTest {
    ...
}

Then I got "java.lang.NoClassDefFoundError: Failed resolution of: Ljava/beans/Introspector;" in PowerMock...

It seems android sdk had removed some Class in java.beans.* https://developer.android.com/reference/java/beans/package-summary.html

How can I mock or fake the static method return values?

Thanks a lot.

Richard
  • 251
  • 2
  • 8
  • You can look this and try.https://stackoverflow.com/questions/15065545/using-jars-that-use-java-beans-classes-introspector-beaninfo-or-propertydescri#15185068[](https://stackoverflow.com/questions/15065545/using-jars-that-use-java-beans-classes-introspector-beaninfo-or-propertydescri#15185068) – KeLiuyue Aug 11 '17 at 03:29
  • It seems there still no solution for lack of java.beans except replace the package locally... – Richard Aug 11 '17 at 03:44

1 Answers1

0

Try going with an older version

def powermock_version="1.6.6" androidTestCompile "org.powermock:powermock-module-junit4:$powermock_version" androidTestCompile "org.powermock:powermock-module-junit4-rule:$powermock_version" androidTestCompile "org.powermock:powermock-api-mockito:$powermock_version"

eTHP
  • 81
  • 2