Selenium的開(kāi)發(fā)提供的SeleneseTestCase是Junit3風(fēng)格的,放在JUnit4底下跑,JUnit4的Annotation功能用不起來(lái)了。Selenium要啟動(dòng)瀏覽器,如果用不上@BeforeClass的話(huà),每次啟動(dòng)都初始化一下Selenium,開(kāi)個(gè)IE或者Firefox,這個(gè)測(cè)試的效率可吃不消(也有比較麻煩的Workaround,但總覺(jué)得不是很好)。而甩開(kāi)SeleneseTestCase的話(huà),又舍不得那個(gè)在測(cè)試沒(méi)有通過(guò)的時(shí)候自動(dòng)截屏的功能。網(wǎng)絡(luò)上有人已經(jīng)有解決方法,我整理如下:、
編寫(xiě)MyRunListener,繼承RunListener
importorg.junit.runner.notification.Failure;
importorg.junit.runner.notification.RunListener;
publicclassMyRunListenerextendsRunListener {
@Override
publicvoidtestFailure(Failure failure)throwsException {
}
}
編寫(xiě)MyRunner類(lèi)
importorg.junit.runner.notification.RunNotifier;
importorg.junit.runners.BlockJUnit4ClassRunner;
importorg.junit.runners.model.InitializationError;
publicclassMyRunnerextendsBlockJUnit4ClassRunner {
privateMyRunListenermyRunListener;
publicMyRunner(Class<?> c)throwsInitializationError {
super(c);
myRunListener=newMyRunListener();
}
@Override
publicvoidrun(RunNotifier rn) {
rn.addListener(myRunListener);
super.run(rn);
}
}
在測(cè)試代碼中引入
@RunWith(MyRunner.class)
publicclassMyhomeTestextendsSeleneseTestCase {
具體的參與地址是: http://rockhoppertech.com/blogs/archives/45