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 8818879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:12:55+00:00 2026-06-14T05:12:55+00:00

When a given JUnit4 test runs, I want it to generate a logfile of

  • 0

When a given JUnit4 test runs, I want it to generate a logfile of all of its TestResults. I do not want to invoke this via CI/ant/maven. I want this to run anytime the JUnit test is called from anywhere. If that is not possible, then I would like to write my own runner which problematically invokes my AllTestSuites class and logs all the results itself.

Here would be one of my test classes:

public class SimpleTestSuite extends TestCase{

    @Test
    public void simpleTestPass() {
        assertTrue(true);
    }

    @Test
    public void simpleTestFail() {
        assertTrue(false);
    }

    @Test
    public void simpleTestException() {
        throw new RuntimeException();
    }

}

I included it in a TestSuite, which contains all of my test Suites to run:

@RunWith(Suite.class)
@Suite.SuiteClasses({SimpleTestSuite.class, ExampleSuite.class,})
public final class AllTestSuites {}

I want to invoke AllTestSuites and have it generate a log file such as below. Remember, I prefer to capture what is on the JUnit4 framework’s result bus, and not to reinvent/create a new test runner.

simpleTestPass - pass - 1/1 assertions passed
simpleTestFail - fail - 0/1 assertions passed
simpleTestException - exception - stacktrace as follows...
  • 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-14T05:12:56+00:00Added an answer on June 14, 2026 at 5:12 am

    Add logger in you Test Class and Base Test Class and define as TestWatchMan as below:

    Logger logger = LoggerFactory.getLogger(TestCase.class);
    @Rule public MethodRule watchman = new TestWatchman() {
       public void starting(FrameworkMethod method) {
          logger.info("Test {} is running.", method.getName());
       }
       public void succeeded(FrameworkMethod method) {
       logger.info("Test {} succesfully run.", method.getName());
       }
       public void failed(Throwable e, FrameworkMethod method) {
            logger.error("Test {} failed with {} reason.", 
                                                    method.getName(), e.getMessage());
       }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In JUnit tests, I need to test that a given object (not the reference,
Using JUnit4, what I want to do is to be able to test a
Given this method to work on a HTML page in a webbrowser: bool semaphoreForDocCompletedEvent;
Given a certain date, I want to set the value of a cell with
Given a MySQL table of real estate data, I would like to generate a
This is not an homework. But an practice to understand what are the best
I noticed that jUnit runs the constructor of my test class for each method
Given a document {'foo', 'bar', 'baz'}, I want to match using SpanNearQuery with the
I've been given a test-driven development problem (I need to make it work based
I have three JUnit test classes that all had some common code, including identical

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.