JUnit Time Test - JUnit

What is test time in Junit?

JUnit provides a handy option of Timeout. Incase if a test case takes more time than the pre-decided number of milliseconds, then JUnit will automatically considered as failed. The timeout parameter is used along with @Test annotation. Here’s how to use the @Test(timeout) in action.

Create a Class

Let’s create a java class to be tested, say, MessageUtil.java in C:\>JUNIT_WORKSPACE.
Add an infinite while loop inside the printMessage() method.

Create Test Case Class

Now create a java test class, say, TestJunit.java. Add a timeout of 1000 to testPrintMessage() test case.
Create a java class file named TestJunit.java in C:\>JUNIT_WORKSPACE.

Create Test Runner Class

Then create a java class file named TestRunner.java in C:\>JUNIT_WORKSPACE to execute test case(s).
Now compile the MessageUtil, Test case and Test Runner classes using javac.
Let’s run the Test Runner, as per the predetermined test cases defined in the provided Test Case class.
Now verify the output. testPrintMessage() test case will mark the unit testing failed.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JUnit Topics