maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jieryn <jie...@gmail.com>
Subject Re: Code coverage with debug logs: 100% branch coverage not possible?...
Date Fri, 14 Feb 2014 12:54:37 GMT
I have also been annoyed with what you describe, and have wondered how
to fill the gap of missing coverage.

Outside of copying the testcase and dynamically changing the log level
inside of it, which in addition to being burdensome, also offends my
DRY sensibility, the best idea I've had about this involves a
relatively new feature of JUnit called @Theories[1].

You could create @DataPoints {Level.ALL, Level.NONE} and then pass
them in to your test method. Then you dynamically set the class under
test's Logger.Level with the data point. I think this ought to work
just fine unless you execute your tests in parallel mode, as most
Logger declarations are as static instances.

There's one other problem which has prevented me from exploiting this
technique: @Theories needs a dedicated @RunWith(Theories.class). Which
would tend to preclude execution under @RunWith(Arquillian.class)
since @RunWith takes a singular runner argument, unless Aslak/someone
makes some tweaks[2].

[1] https://github.com/junit-team/junit/wiki/Theories
[2] https://issues.jboss.org/browse/ARQ-561


On Wed, Feb 12, 2014 at 3:30 PM, Benoît Berthonneau
<benoit@berthonneau.com> wrote:
> Hi all,
>
>
>
> I need your opinion/way to tackle the following problem:
>
> In many projects we use a Logger (doesn't matter which implementation). It
> is often recommend to test if the debug level is activated before logging a
> debug trace like the following:
>
> if (logger.isDebugEnabled()) {
>
>     logger.debug("blah " + i + " in the loop that contains " + max);
>
> }
>
>
>
> Now when you run unit tests on this kind of code you need to make a choice:
> run tests with INFO level or run tests with ALL traces activated. I choose
> the second option in order to:
>
> *         Check that debug traces doesn't throw unwanted exception (like
> NPE)
>
> *         Have a better code coverage in term of covered lines
>
>
>
> But in term of branches coverage we could never have a 100% :(
>
>
>
> To me the only way to cover this is to run the tests suite 2 times: one with
> INFO traces configured, and another one with ALL traces activated.
>
> Did you face this issue and how did you solve it ?
>
>
>
> Thanks,
>
> Benoît.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Mime
View raw message