I have two JUnit4 Test classes say MyTest1, MyTest2 each having a couple of test methods. Actually these are Selenium JUnit TestCases.
In MyTest1.someMethodInsertingDate() i will insert some data into DB and it will take some time to process.
In MyTest2.validateProcessedData() I need to verify that the processed data inserted in the first test method is valid or not.
I know coupling between test methods/cases is not a good practice. But I am writing SeleniumTests to automate User Actions on UI, so I have to do this.
I am executing these two TestCases using MyTestSuite with @RunWith & @SuiteClasses.
Now How can I tell JUnit to execute MyTest2 TestCase with some delay,say 1 minute.
JUnit provides a handy option of Timeout. If a test case takes more time than the specified number of milliseconds, then JUnit will automatically mark it as failed. The timeout parameter is used along with @Test annotation. Let us see the @Test(timeout) in action.
@Ignore annotation can be used in two scenarios as given below: If you want to ignore a test method, use @Ignore along with @Test annotation. If you want to ignore all the tests of class, use @Ignore annotation at the class level.
To specify the timeout period of a certain test case, “timeout” attribute is mentioned on the annotation @Test . Note that the timeout time is specified in milliseconds. In the above test, execution will be timed out after 500ms with the below message.
You can use the simple "@Before" annotation. It should delay the execution thread each time it starts the test.
Example:
@Before
public void initialise() throws InterruptedException {
Thread.sleep(2000);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With