-
Notifications
You must be signed in to change notification settings - Fork 189
Added example for custom expectation-fail message in docs #486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -471,3 +471,55 @@ end; | |
| ``` | ||
| Since NULL is neither *true* nor *not true*, both expectations will report failure. | ||
|
|
||
| # Provide a custom error message | ||
| Expectations allow you to provide a custom error message as second argument: | ||
| ````sql | ||
| ut.expect( a_actual {data-type}, 'custom error message if expectation fails' ).to_{matcher}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you replace the 'error message' with 'failure message' or just 'custom message'. |
||
| ```` | ||
| The message is added to the normal error message returned by the matcher. | ||
|
|
||
| This is not only useful to give more detailed and specific information about a test, but also if you have some kind of dynamic tests. | ||
|
|
||
| ## Dynamic tests example | ||
| You have a bunch of tables and an archive-functionality for them and you want to test if the things you put into live-tables are removed from live-tables and present in archive-tables: | ||
|
|
||
| ````sql | ||
| procedure test_data_existance( i_tableName varchar2 ) | ||
| as | ||
| v_count_real integer; | ||
| v_count_archive integer; | ||
| begin | ||
|
|
||
| execute immediate 'select count(*) from ' || i_tablename || '' into v_count_real; | ||
| execute immediate 'select count(*) from ' || i_tablename || '_archive' into v_count_archive; | ||
|
|
||
| ut.expect( v_count_archive, 'error checking entry-count of ' || i_tablename || '_archive' ).to_( equal(1) ); | ||
| ut.expect( v_count_real, 'error checking entry-count of ' || i_tablename ).to_( equal(0) ); | ||
|
|
||
| end; | ||
|
|
||
| procedure test_archive_data | ||
| as | ||
| begin | ||
| -- Arrange | ||
| -- insert several data into real-tables here | ||
|
|
||
| -- Act | ||
| package_to_test.archive_data(); | ||
|
|
||
| -- Assert | ||
| test_data_existance('TABLE_A'); | ||
| test_data_existance('TABLE_B'); | ||
| test_data_existance('TABLE_C'); | ||
| test_data_existance('TABLE_D'); | ||
| end; | ||
| ```` | ||
| A failed output will look like this: | ||
| ```` | ||
| Failures: | ||
|
|
||
| 1) test_archive_data | ||
| "error checking entry-count of TABLE_A_archive" | ||
| Actual: 2 (number) was expected to equal: 1 (number) | ||
| at "UT_TEST_PACKAGE.TEST_DATA_EXISTANCE", line 12 ut.expect( v_count_archive, 'error checking entry-count of ' || i_tablename || '_archive' ).to_( equal(1) ); | ||
| ```` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To be consistent with the rest of document please change that to: Adding custom failure message