Issue
So I have a test case that I want to make into a thread. I cannot extend Thread nor can I implement runnable since TestCase already has a method void run(). The compilation error I am getting is Error(62,17): method run() in class com.util.SeleneseTestCase cannot override method run() in class junit.framework.TestCase with different return type, was class junit.framework.TestResult
.
What I am trying to do is to scale a Selenium testcase up to perform stress testing. I am not able to use selenium grid/pushtotest.com/amazon cloud at this time (installation issues/install time/resource issues). So this really is more of a Java language issue for me.
FYI: SeleniumTestCase is what I want to make multi threaded to scale it up for stress testing. SelniumTestCase extends TestCase (from junit). I am extending SeleniumTestCase and trying to make it implement Runnable.
Solution
Create a inner class that implements Runnable and call it from a new Thread in com.util.SeleneseTestCase run() method. Something like this:
class YourTestCase extends SeleneseTestCase {
public class MyRunnable implements Runnable {
public void run() {
// Do your have work here
}
}
public void testMethodToExecuteInThread() {
MyRunnable r = new MyRunnable();
Thread t = new Thread(r);
t.start();
}
}
Update to use outside YourTestCase class
To run an inner class from another class you would need to make it public and then from the outer class execute this:
YourTestCase testCase = new YourTestCase();
YourTestCase.MyRunnable r = testCase.new MyRunnable();
But if you don't need to call it from inside your test case you'd better go with a normal class, make MyRunnable a public class without being in YourTestCase.
Hope it helps.
Answered By - Felipe Cypriano
Answer Checked By - Gilberto Lyons (JavaFixing Admin)