我必须使用eclipse用selenium用java编写测试。我遇到了需要同时运行两个浏览器的情况。我知道有TestNG,但现在我用不起它。所以我的问题是,有没有办法
new Thread 只有方法?例如:
package test.test
import...
public class tests {
public Thread t1, t2;
@Before
public void putUp() {
//my code
}
@Test
public void test(){
t1 = new Thread(usingT1);
t2 = new Thread(usingT2);
t1.start();
t2.start();
...//rest of the code
}
public void usingT1(){
//code of that method
}
public void usingT2(){
//code of that method
}
@After
public void putDown(){
//my code
}我知道有一种在Runnable元素中使用类的方法。如果没有使用方法的方法,你可以给我一个简单的例子,因为我发现的所有东西都以一种奇怪的方式显示出来。
Thx求助Janer
发布于 2016-10-24 12:29:41
这很容易做到;例如,通过使用匿名内部类:
Thread thread1 = new Thread( new Runnable() {
@Override
public void run() {
... will happen in its own thread
}
});然后只需对线程对象调用start()即可。
但真正的问题是:这是个好主意吗?但我认为并非如此。你在重新发明方向盘,不管你想出什么.可能不如任何为你做这些事情的现有解决方案那么好。
最后,这取决于A)你的技能和B)你实际上想要做的事情并行。仅仅是你不知道如何做这么简单的事情这一事实让我认为你的技能不适合做你在这里建议的事情。
https://stackoverflow.com/questions/40218272
复制相似问题