-
Notifications
You must be signed in to change notification settings - Fork 583
Closed
Description
Hi PowerMock team,
I have try to use PowerMock with unit test for android.
but failed.
Errors:
/usr/lib/jvm/java-8-oracle/bin/java -ea -Didea.launcher.port=7537 -Didea.launcher.bin.path=/home/snowdream/bin/android-studio/bin -Didea.junit.sm_runner -Dfile.encoding=UTF-8 -classpath /home/snowdream/bin/android-studio/lib/idea_rt.jar:/home/snowdream/bin/android-studio/plugins/junit/lib/junit-rt.jar:/home/snowdream/bin/android-sdk-linux/platforms/android-23/data/res:/home/snowdream/snowdream/git/SnowdreamFramework/modules/core/build/intermediates/classes/test/debug:/home/snowdream/snowdream/git/SnowdreamFramework/modules/core/build/intermediates/classes/debug:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-api-mockito-common/1.6.5/50929570ea185735f8f038ea650a60f6444e7ec3/powermock-api-mockito-common-1.6.5.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.android.support/support-v4/24.1.1/jars/classes.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.android.support/support-v4/24.1.1/res:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.android.support/support-v4/24.1.1/jars/libs/internal_impl-24.1.1.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.20.0-GA/a9cbcdfb7e9f86fbc74d3afae65f2248bfbf82a0/javassist-3.20.0-GA.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-exec/1.3/8dfb9facd0830a27b1b5f29f84593f0aeee7773b/commons-exec-1.3.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-module-junit4-common/1.6.5/ef0b8507142b3c176d1b8a1937a8490eaf8babe9/powermock-module-junit4-common-1.6.5.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/core/libs/annotations.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.getkeepsafe.relinker/relinker/1.2.1/jars/classes.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.getkeepsafe.relinker/relinker/1.2.1/res:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.1/905075e6c80f206bbe6cf1e809d2caa69f420c76/commons-lang3-3.1.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-reflect/1.6.5/3569903763e7741965acc9627ad8253d210feedf/powermock-reflect-1.6.5.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.labo.kaji/fragmentanimations/0.1.0/jars/classes.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.labo.kaji/fragmentanimations/0.1.0/res:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-api-mockito2/1.6.5/182ba283e5bae347b9ec85a8c7c8ba13e6a05752/powermock-api-mockito2-1.6.5.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-api-support/1.6.5/9b0cdf26351d3608a1bf11d3a5b8c96e9c32605/powermock-api-support-1.6.5.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy/1.4.8/91562a3d78dbadb5bb66bd25c3244783368b1ad8/byte-buddy-1.4.8.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/2.4/2916b6c96b50c5b3ec4452ed99401db745aabb27/objenesis-2.4.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.desarrollodroide/fragmenttransactionextended/1/res:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.desarrollodroide/fragmenttransactionextended/1/jars/classes.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-core/2.0.87-beta/7f458fbd2bc966c7684b5ad2fb7a87222cabf47b/mockito-core-2.0.87-beta.jar:/home/snowdream/bin/android-sdk-linux/extras/android/m2repository/com/android/support/support-annotations/24.1.1/support-annotations-24.1.1.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3/res:/home/snowdream/snowdream/git/SnowdreamFramework/modules/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3/jars/classes.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/app/build/intermediates/exploded-aar/com.android.support/multidex/1.0.1/res:/home/snowdream/snowdream/git/SnowdreamFramework/modules/app/build/intermediates/exploded-aar/com.android.support/multidex/1.0.1/jars/classes.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-module-junit4/1.6.5/e6ad8d4fddb3cc1e11ebf343ecc82ea10b12d5a4/powermock-module-junit4-1.6.5.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.kogitune/pre-lollipop-activity-transition/1.3.0/jars/classes.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/main/build/intermediates/exploded-aar/com.kogitune/pre-lollipop-activity-transition/1.3.0/res:/home/snowdream/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-core/1.6.5/5c7f30af24a260b9a452c194be0cca373db9aaf6/powermock-core-1.6.5.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/util/build/intermediates/classes/debug:/home/snowdream/snowdream/git/SnowdreamFramework/modules/app/build/intermediates/exploded-aar/com.android.support/support-v4/21.0.3/res:/home/snowdream/snowdream/git/SnowdreamFramework/modules/app/build/intermediates/exploded-aar/com.android.support/support-v4/21.0.3/jars/classes.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/app/build/intermediates/exploded-aar/com.android.support/support-v4/21.0.3/jars/libs/internal_impl-21.0.3.jar:/home/snowdream/bin/android-sdk-linux/extras/android/m2repository/com/android/support/support-annotations/23.0.1/support-annotations-23.0.1.jar:/home/snowdream/snowdream/git/SnowdreamFramework/modules/log/build/intermediates/classes/test/debug:/home/snowdream/snowdream/git/SnowdreamFramework/modules/log/build/intermediates/classes/debug:/home/snowdream/snowdream/git/SnowdreamFramework/modules/core/build/intermediates/sourceFolderJavaResources/test/debug:/home/snowdream/snowdream/git/SnowdreamFramework/modules/core/build/intermediates/sourceFolderJavaResources/debug:/home/snowdream/snowdream/git/SnowdreamFramework/modules/util/build/intermediates/sourceFolderJavaResources/debug:/home/snowdream/snowdream/git/SnowdreamFramework/modules/log/build/intermediates/sourceFolderJavaResources/debug:/home/snowdream/snowdream/git/SnowdreamFramework/build/generated/mockable-android-23.jar com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.github.snowdream.android.widget.ToastTest,testCreateOrUpdateToastFromToastBean
Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter
at sun.reflect.GeneratedSerializationConstructorAccessor8.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:45)
at org.powermock.reflect.internal.WhiteboxImpl.newInstance(WhiteboxImpl.java:251)
at org.powermock.reflect.Whitebox.newInstance(Whitebox.java:139)
at org.powermock.api.extension.reporter.AbstractMockingFrameworkReporterFactory.getInstanceForClassLoader(AbstractMockingFrameworkReporterFactory.java:41)
at org.powermock.api.extension.reporter.AbstractMockingFrameworkReporterFactory.create(AbstractMockingFrameworkReporterFactory.java:35)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.getMockingFrameworkReporter(JUnit4TestSuiteChunkerImpl.java:140)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:119)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.mockito.exceptions.Reporter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:190)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:71)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 20 more
Process finished with exit code 1
Empty test suite.
Codes:
package com.github.snowdream.android.widget;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.mockito.Mockito.any;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
;
/**
* Created by snowdream on 16-7-24.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Toast.class})
public class ToastTest {
@Test
public void testCreateOrUpdateToastFromToastBean() throws Exception {
mockStatic(Toast.class);
PowerMockito.doReturn(null).when(Toast.class, "createOrUpdateToastFromToastBean", any(android.widget.Toast.class), any(ToastTest.class));
PowerMockito.verifyPrivate(Toast.class).invoke("createOrUpdateToastFromToastBean",null,null);
}
}
I'm building through Android studio 2.1.2 and my dependencies are:
testCompile 'junit:junit:4.12'
// required if you want to use Mockito for unit tests
testCompile 'org.mockito:mockito-core:2.0.87-beta'
// required if you want to use Powermock for unit tests
testCompile 'org.powermock:powermock-module-junit4:1.6.5'
testCompile 'org.powermock:powermock-api-mockito2:1.6.5'
I'm using ubuntu 16.04.