Return-Path: X-Original-To: apmail-maven-users-archive@www.apache.org Delivered-To: apmail-maven-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A0DC71045D for ; Wed, 12 Feb 2014 21:11:01 +0000 (UTC) Received: (qmail 70508 invoked by uid 500); 12 Feb 2014 21:10:57 -0000 Delivered-To: apmail-maven-users-archive@maven.apache.org Received: (qmail 70392 invoked by uid 500); 12 Feb 2014 21:10:57 -0000 Mailing-List: contact users-help@maven.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Maven Users List" Reply-To: "Maven Users List" Delivered-To: mailing list users@maven.apache.org Received: (qmail 70379 invoked by uid 99); 12 Feb 2014 21:10:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Feb 2014 21:10:57 +0000 X-ASF-Spam-Status: No, hits=2.5 required=5.0 tests=FREEMAIL_REPLY,HTML_IMAGE_RATIO_06,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of kjkrum@gmail.com designates 209.85.160.178 as permitted sender) Received: from [209.85.160.178] (HELO mail-yk0-f178.google.com) (209.85.160.178) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Feb 2014 21:10:52 +0000 Received: by mail-yk0-f178.google.com with SMTP id 79so16790976ykr.9 for ; Wed, 12 Feb 2014 13:10:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Z6Oc3JSHjBZABwRHRd2cv5rFsIxZtaOHSlPf6xd+57A=; b=h7wzonbKea3GqNhBQhEHrFSk8MNsytv/ZHsY5Izvk6ywvC9aTmoqEu6sKeLanZvnyt 4pkfr573a/mRmhgYd2JC/KcE1vXfgNsD+zLgmJwL015supSkXcC8Zx0cEblUAxOZK87y PYXukza6F1Ubc6/BQaYM+/ZQSdG9FVGy4AHlf4qZQlT+eCoJNE4+mZCAnKJeg7u6DpBT IAeTvqJEUmkJ2iUemVyVaAdodQXjoTlweCncbRN5kP6Yyrn0jOezbNHv8/wr3D2s+c8d zhgQL9YaVAo4lwcn8z+VGutcd5ieGKuPtVt4Qr2IrbD0W/x/iMy/cQ1xIpr/xsqU7pOr pGlg== MIME-Version: 1.0 X-Received: by 10.236.142.38 with SMTP id h26mr56589yhj.151.1392239431286; Wed, 12 Feb 2014 13:10:31 -0800 (PST) Received: by 10.170.78.133 with HTTP; Wed, 12 Feb 2014 13:10:31 -0800 (PST) Received: by 10.170.78.133 with HTTP; Wed, 12 Feb 2014 13:10:31 -0800 (PST) In-Reply-To: <008101cf2834$fcf8d4d0$f6ea7e70$@berthonneau.com> References: <9e5201cf2831$52f17c60$f8d47520$@berthonneau.com> <008101cf2834$fcf8d4d0$f6ea7e70$@berthonneau.com> Date: Wed, 12 Feb 2014 14:10:31 -0700 Message-ID: Subject: RE: Code coverage with debug logs: 100% branch coverage not possible?... From: Kevin Krumwiede To: Maven Users List Content-Type: multipart/alternative; boundary=20cf303a2d8bbe86e804f23c00ff X-Virus-Checked: Checked by ClamAV on apache.org --20cf303a2d8bbe86e804f23c00ff Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable It does matter which implementation. The main reason it was recommended to check the logging level was because string concatenation can be expensive, and you want to avoid doing it for a message that won't be logged. But if you're using a logging API like slf4j that uses parameter replacement tokens in the message string, if the message isn't logged, the replacement won't be performed and the call will be cheap. On Feb 12, 2014 1:57 PM, "Beno=EEt Berthonneau" wrote: > Hi Paul, > > > > Don't think that I could play with exclusions. Here is an example : > > > > *A Unit Test :* > > > > *The tested class with ALL traces activated:* > > > > *And the same tested class with INFO traces activated:* > > > > > > -----Message d'origine----- > De : paulus.benedictus@gmail.com [mailto:paulus.benedictus@gmail.com] De > la part de Paul Benedict > Envoy=E9 : mercredi 12 f=E9vrier 2014 21:36 > =C0 : Maven Users List > Objet : Re: Code coverage with debug logs: 100% branch coverage not > possible?... > > > > IIRC, there should be an option in Emma/Cobertura that allows you to > exclude coverage on certain classes. So if you can exclude your log4j > classes (you don't really want to test your logging, do you?), then you > should be able to raise your percentage. > > > > > > On Wed, Feb 12, 2014 at 2:30 PM, Beno=EEt Berthonneau > > 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 (lik= e > > > 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=EEt. > > > > > > > > > > > > -- > > Cheers, > > Paul > --20cf303a2d8bbe86e804f23c00ff--