我读到junit可以在没有main()方法的情况下运行,但我想为我的测试创建一个jar文件。如何从Main()方法调用我的测试?有没有其他方法可以为测试用例创建jar文件?我的代码如下:
public class LoginClass {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://erp.company.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testERPLogin() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.name("login")).clear();
driver.findElement(By.name("login")).sendKeys("manju.r");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("password");
driver.findElement(By.name("submit")).click();
driver.findElement(By.cssSelector("div.oe_attendance_signout")).click();
}
public static void main(String[] args) {
}
}
答案 0 :(得分:1)
使用JUnitCore.main();
how to export (JUnit) test suite as executable jar
与以下答案是一个非常相似的问题:
public static void main(String[] args) throws Exception {
JUnitCore.main(
"com.stackoverflow.MyTestSuite");
}