Can JUnit's timeout message be controlled?

Suppose I have a JUnit unit test that has two parts to it and I don't want to separate the parts into separate @Test methods. Suppose also that I want a timeout parameter for the test.

How can I change/intercept/control the timeout assertion failure message to indicate which part of the test timed out?

Here's an attempt that does not work:

@Test(timeout = 1000)
public void test() {
    try {
        // part one of the test
    } catch (Throwable e) {"Part one failed");

    try {
        // part two of the test
    } catch (Throwable e) {"Part two failed");


Just reading up on the documentation, no. The timeout automatically fails the test. This isn't throwing an exception -- it's done by the test runner. It's possible that you could write your own test runner, but you're still going to have troubles finding out where it failed. I would suggest structuring your test differently. Possibly have your own timer that just fails the test.

Need Your Help

Algorithm to check availability with two time frames

c# c#-4.0

What would be the best algorithm to check the availability of a device for rental with two time frames?

Automatic Credit Card payment authorization

e-commerce payment-gateway payment credit-card payment-processing

Some agency of webhosting, allow automatic credit card payment every year without entering each time the credit card number and CCV code.