Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8565637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:28:18+00:00 2026-06-11T17:28:18+00:00

Consider a JUnit method within a JUnit class. It has some tests and some

  • 0

Consider a JUnit method within a JUnit class. It has some tests and some logger.info/debug statements or whatever. Maybe you don’t log inside Junit methods, but I do and it saves me lots of hassles for quickly knowing why some tests failed.

I would like to ‘erase’ those log statements if the method reaches the end, possibly with SLF4J

A simple way to implement that would be to

logger.tick();

Tells logger to flag further log statements.

logger.tack();

Erase all the log statements up to the tick flag. Problem is that you cannot erase stuff on the Eclipse Console ;).

This would make my life much happier now that i’m using Continuous JUnit Testing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:28:20+00:00Added an answer on June 11, 2026 at 5:28 pm

    I won’t feel self conscious about logging inside unit tests but I imagine most people do alright with the logging facility built into the Unit test framework already. However if you wanted to implement this, you need to capture logs in a variable (some might suggest a StringBuilder) and then dump them at the end of the test based on some dead man’s switch (so if the switch isn’t hit the last act of the unit test is to dump the held back log).

    An example might look like this:

    public abstract class LoggedTest extends TestCase {
      protected boolean displayLog;
      protected StringBuilder log;
    
      public void tick() {
        displayLog = true;
      }
    
      public void tack() {
        displayLog = false;
      }
    
      public void log(String msg) {
        log.append(message);
      }
    
      protected void setUp() {
        displayLog = false;
        log = new StringBuilder();
      }
    
      protected void tearDown() {
        if(displayLog) {
          System.err.println(log);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this example - I have a class called Report that has a field
What would you consider best practice for organizing JUnit tests in a project, and
I have found that the following : <junit haltonfailure=no haltonerror=no > <!-- some tests
Consider the following scenario: The class TemplateActivity extends Activity . Within onResume() it performs
Consider the following code: template <class x1, class x2 = int*> struct CoreTemplate {
Consider the following Mechanize form object #<Mechanize::Form {name f1} {method POST} {action f.php} {fields
Consider the following script for outputting some XML code: var xmlAsString = '<?xml version=1.0?><person><name
Consider the following situation: public class Storage { public T GetSingleByID<T>(long id) where T
Writing Junit Tests for my spring application. Because I am new at this I
Consider: Public MustInherit Class Column Public ReadOnly Property ReturnSomethingUseful() As Object Get 'return something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.