-1

I want to get the Code Coverage of some simple test, which gets data from a DataProvider. I need the coverage result for each data that runs through the test. For example:

if (value != 0)
{
   //do something
}

if (value == 100) {
   //do something
}
   //else do something

If the test gets a value like 0 from the DataProvider, it never reaches the first part of the code, so the coverage result is different than if the value was 100. So how do I get those coverage results for each data? I am using jacoco with the maven plugin...

It maybe would help, if there is a possibility to run the subtests with maven... Currently I am doing this:

mvn test

but I want to do something like this:

mvn -Dtest=myTestClass#myTest#myData (#myData of course not working)

However IntelliJ uses this parameter to specifiy the subtest:

java.exe -ea [.......] @name0 //-> to run the test only with first Data
java.exe -ea [.......] @name1 //-> to run the test only with second Data
etc.

Thanks for your help in advance!

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66

1 Answers1

0

Code coverage is the percentage of code which is covered by automated tests. Code coverage measurement simply determines which statements in a body of code have been executed through a test run, and which statements have not. https://confluence.atlassian.com/clover/about-code-coverage-71599496.html

You can pass the arguments from command line and then run your tests. You can pass them on the command line like this

mvn test -Dtest=<ClassName> -Dvalue=100

then access them in your test with

int value=Integer.valueOf(System.getProperty("value"));
Gurwinder Singh
  • 214
  • 1
  • 12