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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:06:33+00:00 2026-06-16T12:06:33+00:00

I am running a JUnit 4 test using @RunWith(value = Parameterized.class) . This works

  • 0

I am running a JUnit 4 test using @RunWith(value = Parameterized.class). This works fine, no problems there. However, when any of my 34 tests timeout, I only get the message java.lang.Exception: test timed out after 15000 milliseconds. I want it to also show the parameter of the test.

I have even tried to do it like the code below (which I know is a horrible solution for most cases, I just wanted to see if I could get the message to show any time at all), but that did not work, it still resulted in the message above.

private String parameter;

@Test(timeout = 15000)
public void solveAll() {
    try {
        // ... do something that might take a long time
    }
    catch (Throwable e) {
        Assert.fail(this.parameter + " failed! Because of " + e.getMessage());
    }
}

How can I make JUnit also show this.parameter when the test results in a timeout ?

Here is a very simple example test class that shows this problem:

public class ShowMyMessageTest {
    @Test(timeout=1000)
    public void test() {
        try {
            Thread.sleep(3000);
        }
        catch (Throwable e) {
            Assert.fail("Timeout reached with value 42");
        }
    }
}

With this ShowMyMessageTest I sometimes get the expected “Timeout reached with value 42”, and sometimes I get only “java.lang.Exception: test timed out after 1000 milliseconds”. I want to always get “Timeout reached with value 42” in this case.

  • 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-16T12:06:35+00:00Added an answer on June 16, 2026 at 12:06 pm

    This is a bit of a hack, but you could use @After to check the state of the parameter:

    @RunWith(Parameterized.class) public class FooTest {
      private boolean flag = true;
      private String param;
    
      public FooTest(String param) {
        this.param = param;
      }
    
      @Test(timeout = 1000) public void test() {
        while(true == flag);
        param = null;
      }
    
      @After public void after() {
        Assert.assertNull("Problem:" + param, param);
      }
    
      @Parameters public static Collection<Object[]> params() {
        Object[][] params = { { "foo" } };
        return Arrays.asList(params);
      }
    }
    

    An alternative is to write your own runner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using data-driven test suites running JUnit 3 based on Rainsberger's JUnit Recipes
When running a JUnit test, using IntelliJ IDEA, I get How can I correct
Running the Java Compiler from a JUnit test is pretty simple using the Java
I'm running JUnit via Ant using a target something like this: <target name=junit depends=compile>
I am using JUnit 4.10 for running test suites, and I have implemented a
I am running a Junit test case on my eclipse application that was built
I'm adding a Junit test to one of my classes using NetBeans 6.7.1, I
I am trying to execute a SQL script in my JUnit test using Spring.
I put up an Ant project which includes a unit test using JUnit. The
Is there a way of getting JUnit tests in Eclipse (specifically I'm using SpringJUnit4ClassRunner

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.