Junit+Powermockito+jacoco

Hi Team
We are using Junit and PowerMockito to write the test cases.
Code coverage is not getting increased if We use Junit+Powermockito, however, if we use only Junit then code coverage is getting increased.
There are some solutions to appear the code coverage and its stats increase, when we use PowerMockito, please?
jacoco.version=0.8.4
powermock.version= 2.0.2

We include it as well in the pom.xml after ‘jacoco’ plugin definition.

	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-surefire-plugin</artifactId>
:
:
              <argLine>@{jacocoArgLine}
	-javaagent:${settings.localRepository}/org/powermock/powermock-module-javaagent/${powermock.version}/powermock-module-javaagent-${powermock.version}.jar
	-noverify</argLine>
	</configuration>
</plugin>

As recommended in the Sonar documentation. But isn’t working.

What else can we do to increase code coverage?
You have examples of projects with this type of problem, in which the tests with Powermockito do not help to increase the code coverage.
Regards

Hi,

For coverage, we rely on the reports you feed into analysis. Can you verify that your PowerMockito tests show up in your coverage reports?

 
Ann

Hi Ann
Hope you are well
As I mention before our issue is that some of our tests are not working as expected because give us 0% codecoverage. Other are able to cover a 13.26%
For us is a little struggle the use Junit+Powermockito+jacoco
I put an example I have this test:

@RunWith(PowerMockRunner.class)
@PrepareForTest({ VaultS3Connector.class })
public class VaultS3ConnectorTest {
	
	private static String pwd = "password";
	FileService fileServiceImpl;
	CountDownLatch countDownLatch;
	AmazonS3 amazonS3;
	KafkaTopiConfig kafkatopicConfig;
	DocumentCountConfig dcc;
	VaultS3Connector vaultS3Connector;
	List<String> fileContent;
	TransferManager transferManager;

	@Before
	public void setup() {
		fileServiceImpl = PowerMockito.mock(FileServiceImpl.class);
		countDownLatch = PowerMockito.mock(CountDownLatch.class);
		vaultS3Connector = PowerMockito.spy(new VaultS3Connector());
		amazonS3 = PowerMockito.mock(AmazonS3.class);
		kafkatopicConfig = PowerMockito.mock(KafkaTopiConfig.class);
		dcc = PowerMockito.mock(DocumentCountConfig.class);
		transferManager = PowerMockito.mock(TransferManager.class);

		fileContent = new ArrayList<>();
		fileContent.add("xx.pdf");
		fileContent.add("xxx.pdf");
	}
	
	@Test
	public void updateS3andKafkaConfig_success_test() throws Exception {

		PowerMockito.whenNew(KafkaTopiConfig.class)
				.withArguments(Mockito.anyString(),....))
				.thenReturn(kafkatopicConfig);
		PowerMockito.whenNew(CountDownLatch.class).withArguments(Mockito.anyInt()).thenReturn(countDownLatch);
		PowerMockito.whenNew(DocumentCountConfig.class).withNoArguments().thenReturn(dcc);
		
		PowerMockito.stub(PowerMockito.method(VaultS3Connector.class, "validateKafkaConfig")).toReturn(null);
		PowerMockito.stub(PowerMockito.method(VaultS3Connector.class, "generateAmazonS3")).toReturn(amazonS3);
		PowerMockito.stub(PowerMockito.method(VaultS3Connector.class, "validateFileSize")).toReturn(fileContent);
		PowerMockito.stub(PowerMockito.method(VaultS3Connector.class, "checkAndRemoveIfFileExists")).toReturn(null);
		PowerMockito.stub(PowerMockito.method(VaultS3Connector.class, "validateS3Bucket")).toReturn(null);
		PowerMockito.stub(PowerMockito.method(VaultS3Connector.class, "uploadFileIntoS3BucketAndKafka")).toReturn(true);
		PowerMockito.stub(PowerMockito.method(VaultS3Connector.class, "getStats")).toReturn(null);
		PowerMockito.stub(PowerMockito.method(VaultS3Connector.class, "removeProxyForEndpoint")).toReturn(null);
		
		PowerMockito.when(dcc.getNumberProcessed()).thenReturn(6);
		PowerMockito.when(fileServiceImpl.deletefile(Mockito.anyString())).thenReturn("file.csv");
		PowerMockito.doNothing().when(countDownLatch).await();
		boolean value = VaultS3Connector.updateS3andKafka("src/test/resources/updateS3andKafka", "password",
				"file.csv", "....");
		assertTrue(value);

	}
	
	

------------- but can’t test any line any codecoverage as you can see in the attach ---------------

We don’t know what is wrong with the test.
Regards

Hi,

Sorry, but debugging your tests is out of scope for this community. Perhaps there’s a PowerMockito group you can ask?

 
Ann