How can I run automated bdd UI tests using NUnit and SpecFlow in particular order driven by categories

懵懂的女人 提交于 2019-12-10 18:46:12

问题


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

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.

I see that NUnit is running the tests in alphabetical order but this does not solve my issue because of:

  • 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 problem occurs when i am trying to press Run all tests

The expected result is : Tests should pass

The actual result is : Tests are failing

They pass only if they are started and runned by right click on the category and run selected tests.

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.

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.

This pushes me to ask in stackoverflow about some other opinion of an experienced QA.

I will appreciate your help very much !!


回答1:


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.

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).

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.



来源:https://stackoverflow.com/questions/36720866/how-can-i-run-automated-bdd-ui-tests-using-nunit-and-specflow-in-particular-orde

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!