It seems the answer to this question is that no, it is not possible to use literal angle brackets with Specflow's Gherkin parser.
Can angle brackets be escaped in Gherkin (SpecFlow) scenario outline steps?
题
I have a scenario outline in which I need to include literal angle brackets:
Given I have sent "MAIL FROM:<user@example.com>"
When I send "<command>"
Then I should get a <code> reply
Examples:
| command | code |
| RCPT TO:<bogus> | 5xx |
| RCPT TO:<valid> | 2xx |
Is it possible to escape the angle brackets around user@example.com
so that it is not treated as a placeholder?
解决方案 2
其他提示
This reads like a very technical definition of your problem, certainly not something that has resulted from a conversation with somebody in your business department. While there is nothing to stop you running your unit testing using a Specification By Example style, it isn't really what it is designed for. Gherkin is supposed to be a natural language representation of the problem space, and just like English I find it struggles with more precise definitions such as colon less than user at example dot com greater than.
You could just change your binding definitions to make them a little more relaxed
Instead of using
[Given("I have sent (.*)")]
public void IHaveSent(string line)
{
DoSomethingWith(line);
}
Try
[Given("I have sent mail from (.*)")]
public void IHaveSentMailFrom(string email)
{
DoSomethingWith(string.Format("MAIL FROM:<{0}>");
}
So it becomes more like
Given I have sent mail from user@example.com
However you will get far greater benefit, if you define the example more fully. Instead of user@example.com let's call him Bill and define (outside of the Gherkin) what we think Bill is trying to do. E.g. Bill might be trying to do the valid scenarios, while Ted might me attempting the bogus ones.
Given I have an email from Bill
When I get a receipt
Then it should be valid
Given I have an email from Ted
When I get a receipt
Then it should be bogus