问题描述
我需要通过持续集成来运行自动化UI测试的帮助.我大约有200个测试用例,但是它们并不是按照一些好的做法编写的,它们是相互依赖的.我不是开发人员,也不是质量检查人员,也不知道详细情况,因此,如果我不适合做某件事,请原谅.这就是我所看到的:
I need help running an automated UI tests by Continuous integration. I have around 200 test cases but they are not written following some good practices and they are depending each other. I am a dev not a QA and I don't know what is happening in details so excuse me if i am not right for something. This is what i can see :
1. The tests are BDD
2. They are written with SpecFlow
3. NUnit is used as test executor
系统有点复杂,很难编写没有依赖项的测试,但并非不可能,因为这样的想法是,编写测试的人对事情应该如何发生并不了解.我需要一些可能的最简单解决方案的帮助,以便在测试机上运行这些UI测试.
The system is a bit complicated and it is hard to write tests without dependencies but not impossible the idea is that the person, who has wrote them does not have a good knowledge of how the things should happen. I need some help for the simplest solution possible in order to run those UI tests on a test machine.
我看到NUnit正在按字母顺序运行测试,但这由于以下原因不能解决我的问题:
I see that NUnit is running the tests in alphabetical order but this does not solve my issue because of:
- 将质量检查逻辑上按类别插入案件
- 为了避免代码重复而编写测试时,QA在同一类别中插入了多个案例-例如:我们有一个类别 CAT 和一个类别 DOG 以及名为 checkSound 的测试用例.此测试用例同时包含在 CAT 和 DOG 类别中.
- The QA was inserted the cases logically in categories
- When the tests are written in order to avoid code duplication the QA was inserted multiple cases in a same category - for example : We have a category CAT and category DOG and test case that is named checkSound This test case is included in both Categories CAT and DOG.
当我尝试按运行所有测试
预期结果是:测试应通过
The expected result is : Tests should pass
实际结果是:测试失败
只有通过右键单击类别并运行选定的测试来启动和运行它们时,它们才能通过.
They pass only if they are started and runned by right click on the category and run selected tests.
我尝试在自动生成的.cs文件中使用属性[NUnit.Framework.TestCase(TestName ="01")]设置测试名称,但没有成功.
I have tried to set the tests names in the auto-generated .cs file with attribute [NUnit.Framework.TestCase(TestName = "01")] but with no success.
我也尝试过重命名类别,但也失败了.
I have also tried to rename the categories but also failure.
我看到有一个属性[NUnit.Framework.IncludeExclude()],但我不确定这是否是更改自动生成的设计文件的正确方法.
I saw that there is an attribute [NUnit.Framework.IncludeExclude()] but i am not sure that this is the right way changing the autogenerated design file.
这促使我在stackoverflow中询问有关经验丰富的质量检查的其他意见.
This pushes me to ask in stackoverflow about some other opinion of an experienced QA.
非常感谢您的帮助!
推荐答案
首先:请勿编辑生成的.feature.cs
文件,更改将在下次生成时被替换
First: Do not edit the generated .feature.cs
files, and changes will be replaced when they are next generated
以特定顺序运行测试并非易事,这是有充分理由的.您不应该依赖于测试执行顺序,它会使测试运行变脆并使很多挫败感.最好的选择是尽快解决这些依赖性.
Running the tests in a particular order is not easy to do and for good reason. You should not rely on test execution order, it makes for brittle test runs and for much frustration. Your best bet is to address those dependencies as soon as possible.
如果您已经有一组specflow测试,最简单的方法是在测试中创建一个附加步骤,该步骤具有依赖项,该依赖项的调用步骤与依赖项调用的步骤相同.请参阅此答案,以获取有关如何从另一个步骤调用步骤的示例(文档).
The easiest way to do that if you have an existing set of specflow tests is simply to create an additional step in the tests which have the dependencies which calls the same steps as the dependencies call. See this answer for an example of how to call steps from another step (Documentation).
如果这工作太多,那么您可能能够获得所需的一种方法是在CI上仅执行特定类别的测试,然后在完成这些测试之后,运行下一个类别,然后运行下一个等等,直到您已经执行了所有测试.这不是一个理想的工具,但它是一个钝器,但可能会让您开始运行测试.
If this is too much work then one way you might be able to get what you want is to execute just a certain category of tests on the CI, then when these complete, run the next category, then the next etc etc until you have executed all the tests. This is not ideal and is a blunt tool but might be you enoiugh to get your tests to run.
这篇关于如何使用NUnit和SpecFlow按类别驱动的特定顺序运行自动bdd UI测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!