I have a large number of speclow/BDD test cases that makes REST calls. These REST calls works well with content type application/json and application/xml.

But I need to manually change these content type and re-run all the same scenarios every time i need to test for JSON and XML.

Is there way to run all the scenario twice, first run with ContentType application/json and the second run with application/xml.

2

There are 2 best solutions below

0
On

Yes, but there is nothing in Specflow to support it automatically.

Having said that you can easily reuse your steps and write something like

Given I am using JSON
And X 
When Y
Then it should Z

Given I am using XML
And X 
When Y
Then it should Z

Or even

@UsingJSON
Given X 
When Y
Then it should Z

@UsingXML
Given X 
When Y
Then it should Z

Here you detect the which Tag is used in the steps, or even by using Scoped Bindings

0
On

There's no such thing as "BDD test cases"; only examples of how the system behaves, which we sometimes call "scenarios".

I suggest, first, have some conversations around a couple of different examples of the different systems in use. This will help you see if the behaviour really is identical. Capturing these examples will also help any future developers understand where the real need is coming from, and set expectations about which sources are likely to use each encoding.

If you genuinely need to write tests, try wrapping both the JSON and XML parts of your code in integration tests. XML and JSON are technical concerns, and native languages are really, really hard to refactor! So probably you want to use something like NUnit instead.

Now you've got a few examples, which show how your system behaves and also serve to make sure things are wired up properly, and some integration tests that check that it works for both XML and JSON. The integration tests are there for a technical audience. If someone non-technical really wants to check that they're working, just make sure they're named appropriately and give them the URL to your build. Most business folks can read camel-case.

If you absolutely positively have to run every scenario using both JSON and XML, you can make a "JSON" scenario tree and an "XML" scenario tree, use symbolic links or a build script that copies files to ensure they run from the same English/Native-language source, then provide different step definitions that run with XML or JSON respectively. I suspect you'll have an easier time with my first set of suggestions, though.