我有一套测试用例。我想要@BeforeClass
@RunWith(Suite.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@SuiteClasses({test1.class, test2.class})
public class SuiteClass{
public static WebDriver driver;
public static String baseUrl;
public static StringBuffer verificationErrors = new StringBuffer();
@BeforeClass
public static void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://localhost:7070/myproject/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@AfterClass
public static void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
最后我找到了解决方案:)分享给有需要的人
套房类
@RunWith(Suite.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@SuiteClasses({test1.class, test2.class})
public class SuiteClass{
public static WebDriver driver;
public static String baseUrl;
public static StringBuffer verificationErrors = new StringBuffer();
@BeforeClass
public static void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://localhost:7070/myproject/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@AfterClass
public static void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
pom. xml中用于生成报告的条目
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.5</version>
<configuration>
<outputName>TestReport</outputName>
</configuration>
</plugin>
</plugins>
</reporting>
指定Maven目标以执行SuiteClass
site -Dtest=com.test.testcase.SuiteClass
@RunWith(Suite.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@SuiteClasses({test1.class, test2.class})
public class SuiteClass{
public static WebDriver driver;
public static String baseUrl;
public static StringBuffer verificationErrors = new StringBuffer();
@BeforeClass
public static void setUp() throws Exception {
public static WebDriver driver;
public static String baseUrl;
public static StringBuffer verificationErrors = new StringBuffer();
}
@AfterClass
public static void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
尝试以上你知道你做错了什么…
这并不是因为TestSuite没有任何注释。surefire没有选择您的套件的原因是surefire在寻找要运行的测试时只选择具有以下命名约定的类:
1.测试*
2.*测试
3.*测试用例。
如果您按照上述约定更新套件的名称,它将正常工作。