本文介绍了在 testng.xml 中的一个测试中多次包含一个方法以多次执行步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为测试的一部分,我想多次执行一组测试方法.
我正在使用 TestNG 来指定我的测试.我在 testng.xml 文件中指定的测试是这样的:

I want to execute a set of test methods multiple times as part of a test.
I'm using TestNG to specify my tests. The test I have specified in the testng.xml file is this:

<test>
        <classes>
            <class name="AddAppointment">
                <methods>
                    <include name="testLogin" />
                    <include name="addAppointment" />
                    <include name="checkApptForCurrentLocation" />
                    <include name="changeLocation" />
                    <include name="addAppointment" />
                    <include name="checkApptForCurrentLocation" />
                </methods>
            </class>
        </classes>
    </test>

执行此测试后,我看到重复的方法没有被执行.它只执行测试直到'changeLocation'.有人可以提出任何其他解决方案或原因吗?

请注意,我不想使用不同的数据集多次执行这些方法.因此,按照我在网上找到的一些帖子中的建议使用数据提供程序对我没有帮助.因为我遵守严格的命令
提前致谢!

After executing this test, I saw that the repeated methods did not get executed. It executed the test only till 'changeLocation'.Could anyone suggest any other solution or reason why this is not working?

Please note that I don't want to execute the methods multiple times with different set of data. So using dataproviders as suggested in a few posts I found online will not help me. Because I'm following a strict order
Thanks in advance!

推荐答案

TestNG 不是一种编程语言,这样对待它只会导致心碎.addAppointmentchangeLocation 是编程语言中的动词,而不是测试.

TestNG isn't a programming language and treating it as such will just lead to heartbreak. addAppointment and changeLocation are verbs in a programming language, not tests.

看起来您有 3 个测试:登录测试、一个(默认或起始)位置的特定数据组合测试,以及另一个位置的特定数据组合测试.您可以使用依赖项将这些测试粘合在一起,而不是使用方法/包含构造进行排序.

It looks like you have 3 tests: test for login, a test for a certain data combination in one (the default or starting) location, and a test for a certain data combination in another location. You glue these tests together using dependencies rather than sequencing using the methods/include construction.

特别建议你将testLogin设置在一个名为startup的组中,第一个实质性的测试对.第二个实质性测试对第一个实质性测试有方法依赖性.

In particular, I suggest that you set testLogin to be in a group with a name such as startup, and the first substantial test has a group-dependency on startup. The second substantial test has a method-dependency on the first substantial test.

这篇关于在 testng.xml 中的一个测试中多次包含一个方法以多次执行步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 11:32