-
Notifications
You must be signed in to change notification settings - Fork 1.7k
magento/devdocs#: Expected exceptions #4148
Conversation
1. Add information how to cover negative scenarios with expected exceptions to "GraphQL functional testing" Page: https://devdocs.magento.com/guides/v2.3/graphql/functional-testing.html
An admin must run tests on this PR before it can be merged. |
Hi @atwixfirster. Thank you for your collaboration. Please, consider making minor adjustments mentioned in the review. |
I've got this, @shrielenee . This PR expands #4082 |
@atwixfirster please pull in the changes from this PR |
- in the body of test | ||
- in test function annotation | ||
|
||
#### Define exception message expectation in the body of test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete one of the #s. The previous heading was a H2, so this one should be a H3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
``` | ||
|
||
#### Define expected exception message in test function annotation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to a H3 as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
``` | ||
|
||
There is a list of functions which you can use to cover expected exceptions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a list of functions which you can use to cover expected exceptions: | |
Use the following functions to cover expected exceptions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
There is a list of functions which you can use to cover expected exceptions:
Use the following functions to cover expected exceptions:
done
``` | ||
|
||
There is a list of functions which you can use to cover expected exceptions: | ||
- expectException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap the functions with a text code block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge remote-tracking branch 'upstream/master' into expected-exceptions # Conflicts: # guides/v2.3/graphql/functional-testing.md
done |
@@ -193,3 +193,128 @@ try { | |||
$registry->unregister('isSecureArea'); | |||
$registry->register('isSecureArea', false); | |||
``` | |||
|
|||
## Expected exceptions | |||
When it is necessary to cover negative test scenarios and ensure that testing elicits proper responses, define the expected exception message: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest something like this:
Your functional tests should include events that cause exceptions. Since your tests expect an exception to occur, set up your tests so that they elicit the proper responses. You can define expected exception messages either in:
- The body of the test
- The test function annotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented
- in the body of test | ||
- in test function annotation | ||
|
||
### Define exception message expectation in the body of test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Define exception message expectation in the body of test | |
### Exception messages in the body of a test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
``` | ||
|
||
{:.bs-callout .bs-callout-info} | ||
Please note that the exception message expectation should be defined before invoking a logic that generates the exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that the exception message expectation should be defined before invoking a logic that generates the exception. | |
Define the exception message before invoking logic that generates the exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented
{:.bs-callout .bs-callout-info} | ||
Please note that the exception message expectation should be defined before invoking a logic that generates the exception. | ||
|
||
For example, if `customer A` wants to retrieve information about `customer B cart. In this situation, `customer A` will get an error - "`The current user cannot perform operations on cart "XXXXX`", where `XXXXX` - is an unique ID of `customer B` cart. See code below to understand how to cover this example with `expectExceptionMessage` function: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, if `customer A` wants to retrieve information about `customer B cart. In this situation, `customer A` will get an error - "`The current user cannot perform operations on cart "XXXXX`", where `XXXXX` - is an unique ID of `customer B` cart. See code below to understand how to cover this example with `expectExceptionMessage` function: | |
As an example, consider the case where `customer A` tries to retrieve information about `customer B`'s cart. In this situation, `customer A` will get an error: | |
"`The current user cannot perform operations on cart "XXXXX`" | |
where `XXXXX` - is an unique ID of `customer B`'s cart. The following shows how to cover this example with an `expectExceptionMessage` function: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented
} | ||
``` | ||
|
||
### Define expected exception message in test function annotation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Define expected exception message in test function annotation | |
### Exception messages in the annotation of a test function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
*/ | ||
``` | ||
|
||
Example: a customer wants to retrieve information about his own cart but he provides incorrect cart ID. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example: a customer wants to retrieve information about his own cart but he provides incorrect cart ID. | |
In the following query, a customer provides an incorrect cart ID while trying to retrieve information about his own cart. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} | ||
``` | ||
|
||
See the code below how to cover this example with `@expectExceptionMessage` annotation: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the code below how to cover this example with `@expectExceptionMessage` annotation: | |
The `@expectExceptionMessage` annotation provides the text for the exception in this test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your review , @keharper !
I built this file locally and saw that some changes to the spacing need to be made. So I did that, made a few grammatical changes, and also added Atwix as the author, since more than half of the content was contributed by your company in the last couple of weeks. |
- The test function annotation | ||
|
||
### Exception messages in the body of a test | ||
The following examples show two ways how to define expected exception message through `expectExceptionMessage` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following examples show two ways how to define expected exception message through `expectExceptionMessage` function. | |
The following examples show two ways to define an expected exception message with the `expectExceptionMessage` function. |
running tests |
Hi @atwixfirster, thank you for your contribution! |
Thanks for your contribution @atwixfirster |
@keharper the PR contains two labels to indicate the type of changes: Technical and Major update. Please use only one and add whatsnew if needed. |
@keharper add labels to indicate the affected versions. |
This PR is a:
Summary
When this pull request is merged, it will add information to "GraphQL functional testing" page how to cover negative scenarios with expected exceptions.
Additional information
List all affected URLs
Thank you!
whatsnew
Added section about exceptions to GraphQL functional testing.