gpt4 book ai didi

java - AssertEquals 不会停止测试

转载 作者:行者123 更新时间:2023-12-02 06:06:04 34 4
gpt4 key购买 nike

任何人都可以帮助我使用 AssertEquals 吗?

我的测试用例类有以下代码,但在 AssertEquals 失败后,测试继续进行下一个方法,即 createClientTodelete。为什么?

public class Client

{

public String baseUrl = "http://test.abc.com";
public WebDriver driver;

@BeforeTest
public void setBaseURL()
{
driver = new FirefoxDriver();
driver.get(baseUrl);
driver.manage().window().maximize();
}

@Test(priority = 0, description = "verify successful login")
public void verifyLogin()
{
String expectedDashTitle = "oms";
String actualDashTitle = driver.getTitle();

Assert.assertTrue(driver.findElements(By.name("username")).size()>0);
Assert.assertTrue(driver.findElements(By.name("password")).size()>0);

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("123@123");
driver.findElement(By.name("login")).submit();
Assert.assertEquals(actualDashTitle, expectedDashTitle,"Title Not Found!");
}


@Test(priority = 1, description = "verify client is created successfully")

public void createClientTodelete()
{

driver.findElement(By.xpath(".//*[@id='mainMenu']/ul/li[2]/a/span")).click();
Assert.assertTrue(driver.findElements(By.linkText("Create")).size()>0);

driver.findElement(By.linkText("Create")).click();
driver.findElement(By.id("company_name")).sendKeys("TestCompany");
driver.findElement(By.id("contact_person_firstname")).sendKeys("FirstName");
driver.findElement(By.id("contact_person_lastname")).sendKeys("LastName");
driver.findElement(By.id("contact_person_email")).sendKeys("abc@test.com");
driver.findElement(By.id("save")).click();
}

最佳答案

通过查看您的代码,很明显您正在使用 TestNG 进行这些测试。在 TestNG 中,您可以使用“dependsOnMethods”属性,如下所示。

package sample.testng;
import org.testng.annotations.Test;
import org.testng.Assert;


public class SampleTest {

@Test
public void test(){
System.out.println("Executing test 1");
Assert.assertEquals("ABCD", "abc");
}


@Test(dependsOnMethods={"test"})
public void test1(){
System.out.println("Second test runs only if the first one is successful, otherwise its ignored");
//Asserts or whatever
}

}

关于java - AssertEquals 不会停止测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22282049/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com