gpt4 book ai didi

java - 添加 @after 钩子(Hook)会影响包中的所有测试

转载 作者:行者123 更新时间:2023-11-28 21:15:59 27 4
gpt4 key购买 nike

我想为我在包中的一个测试添加@After 钩子(Hook)。当我从此包(不包含@after 定义)运行另一个测试时,@after Hook 从第一个测试运行。这是正确的行为吗?如何仅为该测试添加 @after 钩子(Hook)?

最佳答案

您需要使用带标记的 Hook ,以便您可以选择运行代码的场景,而不是所有场景。如果您共享您的代码,就可以更容易地准确理解您出错的地方,但这是我最好的猜测。

@After("@onlyThisTest")
public void doSomethingOnlyAfterTestsWithThatTag(){
}

参见 the tagged hooked documentation for more detail .

关于java - 添加 @after 钩子(Hook)会影响包中的所有测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58270314/

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