这是一个奇怪的问题,一直在摸不着头脑。
我有(或将要)大量的测试都使用相同的Before并且包含规则。所以我认为我能做的就是把它移到一个基地"类。
所以一切进展顺利。我创建了一些具有单个@Test方法的文件。然后我尝试创建一个具有多种@Test方法的文件(几乎要去google,就是这样。)在Eclipse中,这可以按照我的预期工作。当我尝试在maven中运行相同时,多个文件中只有一个@Tests进入谷歌,其他人什么都没有显示(网址似乎设置为"数据;")在输出maven上显示" GuidancePage_Test.GuidancePageTitleTest NoSuchSession no such session "
我正在使用JUnit 4.12:
我的测试定义为:
public class GuidancePage_Test extends TestBase {
@Test
public void GuidancePageNextButtonPresentTest() throws InterruptedException {
ConfigReader cr = new ConfigReader();
url = cr.getConfigString("Config/Test/Test.properties", "test_URL");
parameters = WebDriverSteps.currentDriver;
steps.openWebPage(url);
steps.logToReport("Hello World");
}
}
基础测试类
公共类TestBase {
public WebDriverSteps steps;
public String url = null;
/**
* @brief Error Collector
*
* We use the ErrorCollector to collect all errors and present them at the end of the test.
* This allows, for example, in data testing for us to have a complete run of all data before
* getting a test fail.
*
*/
@Rule
public ErrorCollector collector = new ErrorCollector();
@Rule
public TestWatcher screenshotOnDemand = new TestWatcher() {
@Override
protected void succeeded(Description description) {
steps.makeScreenshot();
}
@Override
protected void failed(Throwable e, Description description) {
steps.makeScreenshot();
}
@Override
protected void finished(Description description){
steps.quit();
}
};
@Before
public void setUp() {
steps = new WebDriverSteps();
}
//@Parameter("Browser")
public String parameters;
}