powermock

Why PowerMock is attempting to load the server.xml file if the static class is mocked out?

荒凉一梦 提交于 2019-12-11 09:21:13
问题 I am trying to unit test a code that deals with Message Logging which brings in a lot of environmental dependency. This Message Logger is a framework used by all developers across teams. I have used PowerMock for the same since the Logging class is a static class. Though the Junit Unit test runs Green after using Power Mock, it is still attempting to load the server.xml file. The Class calls are as follows Unit Test Class calls -> Static Logger Class calls-> Static Environment Class. This

How make mock of final class?

落花浮王杯 提交于 2019-12-11 08:21:37
问题 Work in AndroidStudio. Want make mock of final class for AndroidInstrumentalTest with PowerMock. Added libs in gradle: androidTestCompile ('org.powermock:powermock-api-mockito:1.5.6') androidTestCompile ('org.powermock:powermock-core:1.5.6') androidTestCompile ('org.powermock:powermock-module-junit4:1.5.6') androidTestCompile 'org.mockito:mockito-core:1.10.8' androidTestCompile 'com.google.dexmaker:dexmaker:1.1' androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.1' Make test class:

java.lang.NoSuchMethodError: org.mockito.Mockito.framework()Lorg/mockito/MockitoFramework

我的梦境 提交于 2019-12-11 07:47:06
问题 I've been facing a peculiar problem. Basically, when I run my Mockito test normally i.e. 'Run as Junit Test', it gives me the following error. Can someone help me please what is my mistake? The error received: java.lang.NoSuchMethodError: org.mockito.Mockito.framework()Lorg/mockito/MockitoFramework; at org.powermock.api.mockito.mockmaker.MockMakerLoader.doLoad(MockMakerLoader.java:45) at org.powermock.api.mockito.mockmaker.MockMakerLoader.load(MockMakerLoader.java:36) at org.powermock.api

PowerMockito tests moved from JDK 1.6 to JDK 1.7 are getting constraint violations

牧云@^-^@ 提交于 2019-12-11 07:38:32
问题 We have some tests that had been working fine with JDK 1.6. We're now moving to JDK 1.7. These tests work fine in Eclipse. When we run these tests from our Ant build, we're seeing errors like this: junit.framework.TestListener: addError(<testmethodname>, loader constraint violation: when resolving overridden method "com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Lorg/w3c/dom/Node;)Ljava/lang/Object;" the class loader (instance of org/powermock/core/classloader

PowerMock + EasyMock: private void method without invokation

跟風遠走 提交于 2019-12-11 06:36:26
问题 Good time! I need to substitute the class' private void method with a mock implementation, and can't to figure out how to do this. I've tried to use such a construction: Test test = PowerMock.createPartialMock(Test.class, "setId"); PowerMock.expectPrivate(test , "setId", EasyMock.anyLong()).andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { return null; } }); PowerMock.replay(test); but the internal PowerMock's class called WhiteBox invokes my "setId" method

Issue when test a Jersey rest service using powermock with Jersey Test + TestNg

我是研究僧i 提交于 2019-12-11 06:11:46
问题 A rest service using Jersey developed. Now I want to write some integration tests for this web service but since not every class being used from the web service is already implemented I need to mock some of them. For example I have the following class: public class ServiceA { public String getService() { return null; }} @Path("/myresource") public class ResourceController { @GET @Produces("text/plain") public String getIt() { ServiceA a = new ServiceA(); return a.getService(); }} Then i want

Mockito + PowerMock + TestNG + Libgdx

僤鯓⒐⒋嵵緔 提交于 2019-12-11 05:32:17
问题 I'm trying add the powermock library to the working project, but I'm getting errors. How I add it: 1) AbsTest extends PowerMockTestCase 2) Build.gradle dependencies 3) In some test add @PrepareForTest({SomeClass.class}) . After this step this error occured. In build.gradle all libraries are included. Error occured in a place where initialize HeadlessApplication for use Gdx.* static vars. All tests in project extend this class: abstract public class AbsTest extends PowerMockTestCase { static {

jacoco only shows coverage for classes in the same module

自作多情 提交于 2019-12-11 03:10:41
问题 I have a somewhat large multi-module Maven project. I have the unit tests in each module being processed by Jacoco. I have a separate child module doing "merge" and "report-aggregate", and this appears to be generating data. I'm even using the generated data in SonarQube. Most of my tests are using PowerMock, and I'm using offline instrumentation. However, after looking closer at the coverage data, I see that it is leaving out coverage data for classes and methods that I know are being

Spock behaving weirdly

限于喜欢 提交于 2019-12-11 02:48:09
问题 RunWith(PowerMockRunner.class) @PrepareForTest(StaticCallInvoke.class) @ContextConfiguration(locations = "file:test/spring/Beans.xml") class TestClass extends Specification{ @Test def "Testing staticMocking"() { setup: def someObject=new SomeObject(); someObject.someValue=100 PowerMockito.mockStatic(StaticCallInvoke.class) when: ClassUnderTest.executeSomething(someObject) then: someObject.someValue=110 /*Wrong Value,It says assertion failed. Thats absolutely fine becuase the value should be

PowerMockito mock static method which throws exception

馋奶兔 提交于 2019-12-10 23:39:30
问题 I have some static methods to mock using Mockito + PowerMock. Everything was correct until I tried to mock a static method which throws exception only (and do nothing else). My test class looks like this: top: @RunWith(PowerMockRunner.class) @PrepareForTest({Secure.class, User.class, StringUtils.class}) body: PowerMockito.mockStatic(Secure.class); Mockito.when(Secure.getCurrentUser()).thenReturn(user); PowerMockito.mockStatic(StringUtils.class); Mockito.when(StringUtils.isNullOrEmpty(