I used only 'command line' in all of these processes and I want to do that.(not using Ant, maven, gradle, etc.)
I would like to run Junit test case and JaCoCo coverage estimation.
First, below is my code
Calculator.java:
public class Calculator {
public int evaluate(String expression) {
int sum = 0;
for(String summand: expression.split("\\+"))
sum += Integer.valueOf(summand);
System.out.println("Hello World!!");
return sum;
}
}
CalculatorTest.java:
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class CalculatorTest {
@Test
public void evaluatesExpression(){
Calculator calculator = new Calculator();
int sum = calculator.evaluate("1+2+3");
assertEquals(6, sum);
}
}
2 java files are in C\Cal and Cal folder contains 4 jar files
(junit-4.12.jar, hamcrest-core-1.3.jar, jacococli.jar, jacocoagent.jar)
In this situation, I maked classfile Calculator.class.
javac Calculator.java
And then, I maked exec (I think it is execution file of jacoco) file to estimate unit-test coverage of Calculator.java file.
java -javaagent:jacocoagent.jar=destfile=jacoco.exec
After that, I extracted the report using the exec file and command
java -jar jacococli.jar report jacoco.exec --classfiles Calculator.class --html "report" --name jacocoReport --sourcefiles "Calulator.java"
However, the test coverage in the html report I made was 0%.
Here is my questions:
Do you know why my coverage is 0%?
Is there any problem in trying to extract the coverage result I want?
When calculating the coverage of the
Calculator.javafile byCalculatorTest.javacode and extracting the report, is it correct to write--classfilesonly usingCalculator.class?There is no difference in the results even if you insert both
Calculator.javaandCalculatorTest.javain--sourcefiles. Did I put it wrong? Or what is the effect of--sourcefiles?
And this is the Internet pages I referenced:

