counting lines on invocation method by reflection

15 views
Skip to first unread message

Philipp Kraus

unread,
Apr 7, 2019, 6:23:17 PM4/7/19
to JaCoCo and EclEmma Users
Hello,

I'm using Jacoco and testing AntLR visitor rules. I have got a parser which does not implement all methods, but these methods return "null", so I would like to check it for the line coverage if they really return null.
So I have written a test with a data provider, which put the parameter class into and the method name:

@Test
@UseDataProvider( "nullrules" )
public void nullreturnrules( @Nonnull final Pair<Class<?>, String> p_rule ) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
{
final ManualVisitor<Object> l_visitor = new CASTVisitorManual();

Assert.assertNull(
l_visitor.getClass().getMethod(
p_rule.getRight(),
p_rule.getLeft()
).invoke(
l_visitor,
Mockito.mock(
p_rule.getLeft()
)
)
);
}

So the pair is for example: ManualParser.TernaryoperationContext.class and "visitTernaryoperation"

How can I tell JaCoCo agent that it should count the coverage?

Thanks

Phil

Marc Hoffmann

unread,
Apr 8, 2019, 6:44:58 AM4/8/19
to jac...@googlegroups.com
Hi Phil,

when the method was actually executed it should be marked as covered, Hard to tell from the snippets what’s going wrong here.

Please provide a executable minimal reproducer (preferably a GitHub repo) where we can analyze the issue.

Regards,
-marc


--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/c9881d62-192f-4527-963d-892a20cb5afb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evgeny Mandrikov

unread,
Apr 8, 2019, 6:54:21 AM4/8/19
to JaCoCo and EclEmma Users


On Monday, April 8, 2019 at 12:23:17 AM UTC+2, Philipp Kraus wrote:

How can I tell JaCoCo agent that it should count the coverage?


If your question is about how to use agent, then answer is: by starting JVM that executes test with the agent as described on page https://www.jacoco.org/jacoco/trunk/doc/agent.html
otherwise please clarify question.

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages