2 Minutes To Code (β Version)

JUnit 4.10 - 2 minute tutorial

Testing for timeout : Test whether code completes within timeout period

If your application code is supposed designed be completed within a given time period, you can test for this by passing the timeout period in milliseconds in the parameter "timeout" to the Test annotation.

If the test ed method takes more than the supplied time period, then junit reports that the test failed.

The trivial example below is required to take less tahn 100 milliseconds.
package com.techfundaes.junit4Bag;

import org.junit.Test;

public class TestTimeout
{
	@Test ( timeout = 100 )
	public void testTransactTimeout()
	{
		try
		{
			Thread.sleep(1000); // Placeholder code for a network activity with latency
		}
		catch (Exception e)
		{
			//e.printStackTrace();
		}
	}
}