Java 在Junit中分离测试用例而不重复
我已经写了一个登录Facebook的基本测试。之后,我想写另一个测试用例,发布一个状态。我想为此创建一个新函数,但如何在不重复整个登录过程的情况下实现这一点呢Java 在Junit中分离测试用例而不重复,java,function,junit,automated-tests,Java,Function,Junit,Automated Tests,我已经写了一个登录Facebook的基本测试。之后,我想写另一个测试用例,发布一个状态。我想为此创建一个新函数,但如何在不重复整个登录过程的情况下实现这一点呢 @Test public void Facebook_LoginTest() { String title= null; // And now use this to visit facebook driver.get("http://www.facebook.com ");
@Test
public void Facebook_LoginTest() {
String title= null;
// And now use this to visit facebook
driver.get("http://www.facebook.com ");
// Find the text input element by its name
WebElement id = driver.findElement(By.id("email"));
WebElement password = driver.findElement(By.id("pass"));
WebElement login = driver.findElement(By.id("loginbutton"));
// Enter something to search for
id.sendKeys("id@blah.com");
password.sendKeys("blahblahblah");
将登录过程移动到测试初始化方法(用@Before注释)或Fixture初始化方法(用@BeforeClass注释)