Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Junit中分离测试用例而不重复_Java_Function_Junit_Automated Tests - Fatal编程技术网

Java 在Junit中分离测试用例而不重复

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 ");

我已经写了一个登录Facebook的基本测试。之后,我想写另一个测试用例,发布一个状态。我想为此创建一个新函数,但如何在不重复整个登录过程的情况下实现这一点呢

        @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注释)