Short answer: you should not do this.
Cucumber tests should be user-friendly and readable. They describe features. The user does not care about whether the error result matches some known byte of the value for the byte.
You need to ask yourself: what am I testing? Respond to an error message? Probably no. You are testing some features in your application. If all you really want is to make sure that this fails, then what you want in your Cucumber script is the following line:
Then the exit status should not be 0
This assumes that the script follows standard conditions, according to which a non-zero exit status signals an error.
If your script requires a specific message to be output, you can add it:
Then it should fail with """ Some error message """
but this is not necessarily the whole conclusion, but only a partial coincidence. (Note that βit should crash for sure:β is defined in Aruba, but I do not recommend using it.)
Change You changed your example to testing, not failure, but my basic tips are the same:
- Separate output specificity from script logic. Using the example in the comments, if you have a test that confirms that you can display one user-created comment, and another test that confirms that you will output the correct 100 comments, then this is enough, you do not need to have 100 comments for the release in the script Cucumber.
- Save Cucumber scripts written from a user perspective. Each script should check what is important to the user. Try to keep them minimal by removing everything that leaks from the implementation when the user doesn't care.
- Use Aruba's built-in constructs that check for partial matches to achieve this. Look for keywords or phrases in the output. Not only are Cucumber tests easier to read, they will be more reliable and immune to unrelated release changes.
source share