gpt4 book ai didi

java - 如何使用 Factory 在 TestNG 中仅包含特定方法

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

使用 TestNG,可以在 testng xml 文件中包含/排除特定方法,如下所示:

<classes>
<class name="WebTest">
<methods>
<include name="testMethod1"/>
</methods>
</class>
</classes>

当使用工厂提供 WebTest 实例时,文档指出您应该只在 xml 中包含工厂类,如下所示:

<classes>
<class name="WebTestFactory" />
</classes

问题是,当使用工厂时,TestNG 运行类 WebTest 的所有带注释的方法。我想做的是这样的:

<classes>
<class name="WebTestFactory">
<methods>
<include name="testMethod1"/>
</methods>
</class>
</classes>

其中 testMethod1 是属于 WebTest 类的方法,并且 WebTest 的实例由 WebTestFactory 返回。

但是,每当我尝试此 TestNG 时,都会提示 WebTestFactory 不包含 testMethod1

在 TestNG 中使用工厂时,有没有办法在 XML 文件中指定方法包含/排除?

最佳答案

据我所知,不可能从工厂过滤方法。当您在同一个类中混合工厂和测试方法时,将使用包含/排除。我开了一个关于需求的工单:https://github.com/cbeust/testng/issues/1253欢迎在那里发表评论。

作为解决方法,您可以尝试实现 a method interceptor这将根据您的业务逻辑(例如系统属性)禁用测试方法。

关于java - 如何使用 Factory 在 TestNG 中仅包含特定方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40766863/

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