gpt4 book ai didi

java - 防止特定方法在 TestNG 测试中使用 AfterMethod

转载 作者:太空宇宙 更新时间:2023-11-04 07:39:56 25 4
gpt4 key购买 nike

简单的问题 - 我的 TestNG 测试类中有这样的 AfterMethod

@AfterMethod
public void tearDown() throws Exception {
userService.deleteUser(userName);
}

所有方法都按预期使用它,但有一个丑陋的家伙

    @Test
public void testDeleteUser() throws Exception {
createUser();
assertNotNull(userService.findByUserName("user01"));
userService.deleteUser(userName);
assertNull(userService.findByUserName("user01"));
}

他不需要AfterMethod,所以我收到这样的消息

java.lang.IllegalArgumentException: attempt to create delete event with null entity

在此测试方法末尾向实体添加一些内容可以实现缓存异常的目的,但我正在寻找专业的解决方案来强制某些方法在类设置中使用 After 或 Before 方法(因此我不需要任何带有组的外部 xml)。

最佳答案

将 testDeleteUser() 移至单独的类。

关于java - 防止特定方法在 TestNG 测试中使用 AfterMethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16223492/

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