powermock

How to get Powermock to work with Dexmaker

 ̄綄美尐妖づ 提交于 2019-12-19 16:18:24
问题 I am trying to incorporate Powermock as a dependency for my Android tests using the following build.gradle configuration: dependencies{ compile 'com.android.support:appcompat-v7:21.0.+' androidTestCompile('org.mockito:mockito-core:1.9.5') androidTestCompile('com.google.dexmaker:dexmaker:1.2') androidTestCompile('com.google.dexmaker:dexmaker-mockito:1.2') androidTestCompile('org.powermock:powermock-module-junit4:1.5.5') { exclude module: 'junit' } androidTestCompile('org.powermock:powermock

How do I mock a private field using PowerMockito? [duplicate]

老子叫甜甜 提交于 2019-12-19 12:01:41
问题 This question already has answers here : How do I test a private function or a class that has private methods, fields or inner classes? (51 answers) Closed last year . The solution proposed as a duplicate is not a PowerMockito solution and as a consequence does not answer this question. Further, this question IS answered legitimately below. IDK if this is a duplicate or not but I sure can't find the item in question if it is. I keep expecting this to be really simple, since it is pretty

PowerMock + Emma - code coverage showing 0% for private static methods and other methods too [duplicate]

梦想与她 提交于 2019-12-19 11:17:25
问题 This question already has answers here : PowerMock ECLEmma coverage issue (7 answers) Closed last year . I have taken a reference of PowerMock from : Mock private method using PowerMockito and applied the same logic here. Also, I installed EMMA (open source tool) in eclipse/STS, but when I run the code I see zero % code coverage. why ? public class MyClient { public void publicApi() { System.out.println("In publicApi"); int result = 0; try { result = privateApi("hello", 1); } catch (Exception

PowerMock + Emma - code coverage showing 0% for private static methods and other methods too [duplicate]

烂漫一生 提交于 2019-12-19 11:16:07
问题 This question already has answers here : PowerMock ECLEmma coverage issue (7 answers) Closed last year . I have taken a reference of PowerMock from : Mock private method using PowerMockito and applied the same logic here. Also, I installed EMMA (open source tool) in eclipse/STS, but when I run the code I see zero % code coverage. why ? public class MyClient { public void publicApi() { System.out.println("In publicApi"); int result = 0; try { result = privateApi("hello", 1); } catch (Exception

Cobertura Showing proper coverage but In sonar many files showing 0% coverage

随声附和 提交于 2019-12-19 10:33:12
问题 I have write multiple JUnit test classes for my project.The code covergae is 80% when I see it in Eclipse using cobertura plugin.But when I try to see my code coverage in Sonar it show only 35%.The reason behind this is that multiple classes have 0% coverage and some classes shows coverage.What is the main reason I don't know.Is it problem of sonar or there is some problem im my code beacuse somewhere I am using PowerMockito somewhere EasyMock and somewhere Mockito. I am attaching the

How to mock static method in Java?

余生长醉 提交于 2019-12-19 08:54:57
问题 I have a class FileGenerator , and I'm writing a test for the generateFile() method that should do the following: 1) it should call the static method getBlockImpl(FileTypeEnum) on BlockAbstractFactory 2) it should populate variable blockList from the subclass method getBlocks() 3) it should call a static method createFile from a final helper class FileHelper passing a String parameter 4) it should call the run method of each BlockController in the blockList So far, I have this empty method:

How can I mock an instance of an enum class with PowerMock & Mockito?

好久不见. 提交于 2019-12-19 06:46:08
问题 I tried to follow the example offered in the answer to this very similar question, but it does not work for me. I get the following error message: java.lang.IllegalArgumentException: Cannot subclass final class class com.myproject.test.support.ExampleEnumerable at org.mockito.cglib.proxy.Enhancer.generateClass(Enhancer.java:447) at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) at org.mockito.cglib.core.AbstractClassGenerator.create

Mockito / Powermockito mock private void method

て烟熏妆下的殇ゞ 提交于 2019-12-19 06:16:21
问题 I need to mock a private void method which takes no arguments using mockito and powermock. The method belongs to a instance which is a spy. I am aware the fact I need to do this suggests bad code but I am working with an old project converting the unit tests from one testing framework to another. If anyone has any suggestions it would be much appreciated. Thank You! So far I have tried this: PowerMockito.doNothing().when(Whitebox.invokeMethod(spy,"method",null)); But I get this error: No

Mockito / Powermockito mock private void method

会有一股神秘感。 提交于 2019-12-19 06:15:03
问题 I need to mock a private void method which takes no arguments using mockito and powermock. The method belongs to a instance which is a spy. I am aware the fact I need to do this suggests bad code but I am working with an old project converting the unit tests from one testing framework to another. If anyone has any suggestions it would be much appreciated. Thank You! So far I have tried this: PowerMockito.doNothing().when(Whitebox.invokeMethod(spy,"method",null)); But I get this error: No

Mock private static final variables in the testing class

我的未来我决定 提交于 2019-12-19 04:48:06
问题 I have a few private static final fields in the class I want to test. Like follows public class ClassToTest{ .... private static final Myclass myclass = MyClassFactory.getMyClass(type.firstType); .... } The type is a enum in the MyClassFactory. That factory do is it initialize object according to type passed and return. My question is does powermock support this and if so how to do this. 回答1: You can use reflection also if any mock library works for you. Field f = classToTest.getclass()