Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4381f75

Browse files
authored
Added example for custom expectation-fail message
Fixes #485
1 parent 008debd commit 4381f75

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

docs/userguide/expectations.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,55 @@ end;
471471
```
472472
Since NULL is neither *true* nor *not true*, both expectations will report failure.
473473

474+
# Provide a custom error message
475+
Expectations allow you to provide a custom error message as second argument:
476+
````sql
477+
ut.expect( a_actual {data-type}, 'custom error message if expectation fails' ).to_{matcher};
478+
````
479+
The message is added to the normal error message returned by the matcher.
480+
481+
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.
482+
483+
## Dynamic tests example
484+
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:
485+
486+
````sql
487+
procedure test_data_existance( i_tableName varchar2 )
488+
as
489+
v_count_real integer;
490+
v_count_archive integer;
491+
begin
492+
493+
execute immediate 'select count(*) from ' || i_tablename || '' into v_count_real;
494+
execute immediate 'select count(*) from ' || i_tablename || '_archive' into v_count_archive;
495+
496+
ut.expect( v_count_archive, 'error checking entry-count of ' || i_tablename || '_archive' ).to_( equal(1) );
497+
ut.expect( v_count_real, 'error checking entry-count of ' || i_tablename ).to_( equal(0) );
498+
499+
end;
500+
501+
procedure test_archive_data
502+
as
503+
begin
504+
-- Arrange
505+
-- insert several data into real-tables here
506+
507+
-- Act
508+
package_to_test.archive_data();
509+
510+
-- Assert
511+
test_data_existance('TABLE_A');
512+
test_data_existance('TABLE_B');
513+
test_data_existance('TABLE_C');
514+
test_data_existance('TABLE_D');
515+
end;
516+
````
517+
A failed output will look like this:
518+
````
519+
Failures:
520+
521+
1) test_archive_data
522+
"error checking entry-count of TABLE_A_archive"
523+
Actual: 2 (number) was expected to equal: 1 (number)
524+
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) );
525+
````

0 commit comments

Comments
 (0)