Reference of AnyDbTest

Content of reference

Standard assertion
Argument direction
Datetime Format

 

Standard assertion for unit testing

AnyDbTest has 39 standard assertions, which can meet most of unit test situation. The following table includes these standard assertions. Plus, most of assertions can prefix ! symbol as logic not operator excluded NotCareResultsetAssertion.

Each assertion should contain 3 elements. One is assertion type, the rest are targetResultset and referenceResultset. You can think assertion type is operator; the targetResultset and referenceResultset are operands.

No. Assertion type Description Operands Passed condition
1 NotCare
Resultset
Ignore to compare targetResultset and referenceResultset Both can be any type succeeded if the targetResultset, referenceResultset, setup and teardown can execute without error.
2 SetEqual Determines whether the targetResultset and the referenceResultset contain the same elements. The SetEquals method ignores duplicate entries and the order of elements in the other parameter. Both are Set style Succeeded if the targetResultset is equal to the referenceResultset; otherwise, false.
3 Overlaps Determines whether the targetResultset overlaps the referenceResultset. Both are Set style succeeded if the targetResultset and the referenceResultset share at least one common element; otherwise, false.
4 IsSupersetOf Determines whether the targetResultset is a superset of the referenceResultset. The targetResultset is a superset of the referenceResultset if every element in the referenceResultset is also in the targetResultset, at least the same number of times. Both are Set style Succeeded if targetResultset is a superset of referenceResultset.
5 IsSubsetOf Determines if targetResultset is a subset of the referenceResultset. The targetResultset is a subset of referenceResultset if every element in targetResultset is also in referenceResultset, at least the same number of times. Both are Set style Succeeded if targetResultset is a subset of referenceResultset.
6 IsProper
SupersetOf
Determines if targetResultset is a proper superset of the referenceResultset. The targetResultset is a proper superset of the refereceResultset if every element in refereceResultset is also in targetResultset, at least the same number of times. Both are Set style Succeeded if targetResultset is a proper superset of referenceResultset.
7 IsProper
SubsetOf
Determines if the targetResultset is a proper subset of the referenceResultset. The targetResulst is a subset of the referenceResultset if every element in the targetResultset is also in the referenceResultset, at least the same number of times. Additional, the targetResultset must have strictly fewer items than the targetResultset. Both are Set style Succeeded if targetResultset is a proper subset of referenceResultset.
8 StrictEqual Determines whether the targatResultset is strictly equal to the referenceResultset, include order and times of every element occurrance Case 1: both are Set style.
Case 2: both are scalar values.
succeeded if the targetResultset is equal to the referenceResultset; otherwise, false.
9 DecimalElement
IsInNumAxis
Determines wheter actual operand is in interval of number axis represented by expected operand actual argument must be decimal list or decimal scalar, and expected argument must be one interval of number axis, such as (0,1) or (0,1] or [0,1) or [0,1]
Note: The min stands for minus infinite, and max stands for infinite.
succeeded if actual operand is in interval of number axis represented by expected operand
10 DecimalElement
IsEqual
Determines wheter actual operand is equal to expected operand actual argument must be decimal list or decimal scalar, and expected argument must be decimal scalar succeeded if actual operand is equal to expected operand
11 DecimalElement
IsGreater
Determines wheter actual operand is greater than expected operand actual argument must be decimal list or decimal scalar, and expected argument must be decimal scalar succeeded if actual operand is greater than expected operand
12 DecimalElement
IsGreaterOrEqual
Determines wheter actual operand is greater than or equal to expected operand actual argument must be decimal list or decimal scalar, and expected argument must be decimal scalar succeeded if actual operand is greater than or equal to expected operand
13 DecimalElement
IsLess
Determines wheter actual operand is less than expected operand actual argument must be decimal list or decimal scalar, and expected argument must be decimal scalar succeeded if actual operand is less than expected operand
14 DecimalElement
IsLessOrEqual
Determines wheter actual operand is less than or equal to expected operand actual argument must be decimal list or decimal scalar, and expected argument must be decimal scalar succeeded if actual operand is less than or equal to expected operand
15 RecordCountIs
InNumAxis
Determines wheter the element count of actual operand is in interval of number axis represented by expected operand actual argument must be one list, and expected argument must be one interval of number axis, such as (0,1) or (0,1] or [0,1) or [0,1]
Note: The min stands for minus infinite, and max stands for infinite.
succeeded if the element count of actual operand is in interval of number axis represented by expected operand
16 RecordCountIs
Equal
Determines wheter the element count of actual operand is equal to expected operand actual argument must be one list, and expected argument must be one list or one decimal scalar succeeded if the element count of actual operand is equal to expected operand
17 RecordCountIs
Greater
Determines wheter the element count of actual operand is greater than expected operand actual argument must be one list, and expected argument must be one list or one decimal scalar succeeded if the element count of actual operand is greater than expected operand
18 RecordCountIs
GreaterOrEqual
Determines wheter the element count of actual operand is greater than or equal to expected operand actual argument must be one list, and expected argument must be one list or one decimal scalar succeeded if the element count of actual operand is greater than or equal to expected operand
19 RecordCountIs
Less
Determines wheter the element count of actual operand is less than expected operand actual argument must be one list, and expected argument must be one list or one decimal scalar succeeded if the element count of actual operand is less than expected operand
20 RecordCountIs
LessOrEqual
Determines wheter the element count of actual operand is less than or equal to expected operand actual argument must be one list, and expected argument must be one list or one decimal scalar succeeded if the element count of actual operand is less than or equal to expected operand

Argument direction

When we will call a stored procedure with arguments, we need to specify the directions of these arguments. The following table lists all types of argument direction.

No. Direction Description Comment
1 Input The argument is an input parameter of an operation such as a stored procedure or SQL statement
2 InputOutput The argument is capable of both input and output.
3 Output The argument is an output parameter.
4 Return The argument represents a return value from an operation such as a stored procedure or SQL statement
5* Anonymous
Output
The argument represents a anonymous output argument, which is not an explicit output argument appeared in stored procedure signature. The order of each argument declaration is very important because the resultsets are retrieved according to the position of argument declaration.
6 ClientSide One ClientSide argument is not a true parameter of statement. Because the kind of argument will be replaced with its value before the statement is submitted on ther DB server. It is very useful to help you create parameterized unit testing case.

5*. In SQL programming perspective, there are two kinds of database whether the database supports anonymous-output argument or not.

e.g. Oracle does not allow anonymous-output in stored procedure, because all resultsets of a stored procedure must be carried by those explicitd Output/Return type arguments. MS SQL Server and MySQL are anonymous-output supported database. You can use Select query statement to return recordset/scalar result in stored procedures in SQL Server and MySQL.

Caution:

  • For database supporting anonymous-output, when there are anonymous-ouput type arguments, the order of each argument declaration is very important because the resultsets are fetched according to the position of argument declaration.
  • For database not supporting anonymous-output, the order of each argument declaration is not relevant at all. Because the resultsets are retrieved according to their argument names.

DateTime Format

When we want to assign value to DateTime type argument, we must give one format pattern of the DateTime value. So and so soly , AnyDbTest can know how to parse the string format into DateTime type.
A datetime format model is composed of one or more datetime format specifiers as listed in Table below. Notice, format specifiers cannot appear twice.
For more information about using a DateTime format specification, see Custom DateTime Format Strings on Microsoft MSDN.

Format specifier Description
d Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero.
dd Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero.
ddd Represents the abbreviated name of the day of the week as defined in the current Region property of Control Panel.
dddd (plus any number of additional "d" specifiers) Represents the full name of the day of the week as defined in the current Region property of Control Panel.
f When you use this format specifier, the number of "f" format specifiers that you use indicates the number of most significant digits of the seconds fraction to parse.
ff Represents the two most significant digits of the seconds fraction.
fff Represents the three most significant digits of the seconds fraction.
ffff Represents the four most significant digits of the seconds fraction.
fffff Represents the five most significant digits of the seconds fraction.
ffffff Represents the six most significant digits of the seconds fraction.
fffffff Represents the seven most significant digits of the seconds fraction.
F When you use this format, the number of "F" format specifiers that you use indicates the maximum number of most significant digits of the seconds fraction to parse.
FF Represents the two most significant digits of the seconds fraction. However, trailing zeros, or two zero digits, are not displayed.
FFF Represents the three most significant digits of the seconds fraction. However, trailing zeros, or three zero digits, are not displayed.
FFFF Represents the four most significant digits of the seconds fraction. However, trailing zeros, or four zero digits, are not displayed.
FFFFF Represents the five most significant digits of the seconds fraction. However, trailing zeros, or five zero digits, are not displayed.
FFFFFF Represents the six most significant digits of the seconds fraction. However, trailing zeros, or six zero digits, are not displayed.
FFFFFFF Represents the seven most significant digits of the seconds fraction. However, trailing zeros, or seven zero digits, are not displayed.
g or gg (plus any number of additional "g" specifiers) Represents the period or era (A.D. for example). This specifier is ignored if the date to be formatted does not have an associated period or era string.
h Represents the hour as a number from 1 through 12, that is, the hour as represented by a 12-hour clock that counts the whole hours since midnight or noon. Consequently, a particular hour after midnight is indistinguishable from the same hour after noon. The hour is not rounded, and a single-digit hour is formatted without a leading zero. For example, given a time of 5:43, this format specifier displays "5".
hh, hh (plus any number of additional "h" specifiers) Represents the hour as a number from 01 through 12, that is, the hour as represented by a 12-hour clock that counts the whole hours since midnight or noon. Consequently, a particular hour after midnight is indistinguishable from the same hour after noon. The hour is not rounded, and a single-digit hour is formatted with a leading zero. For example, given a time of 5:43, this format specifier displays "05".
H Represents the hour as a number from 0 through 23, that is, the hour as represented by a zero-based 24-hour clock that counts the hours since midnight. A single-digit hour is formatted without a leading zero.
HH, HH (plus any number of additional "H" specifiers) Represents the hour as a number from 00 through 23, that is, the hour as represented by a zero-based 24-hour clock that counts the hours since midnight. A single-digit hour is formatted with a leading zero.
m Represents the minute as a number from 0 through 59. The minute represents whole minutes passed since the last hour. A single-digit minute is formatted without a leading zero.
mm, mm (plus any number of additional "m" specifiers) Represents the minute as a number from 00 through 59. The minute represents whole minutes passed since the last hour. A single-digit minute is formatted with a leading zero.
M Represents the month as a number from 1 through 12. A single-digit month is formatted without a leading zero.
MM Represents the month as a number from 01 through 12. A single-digit month is formatted with a leading zero.
MMM Represents the abbreviated name of the month as defined in the current Region property of Control Panel.
MMMM Represents the full name of the month as defined in the current Region property of Control Panel.
s Represents the seconds as a number from 0 through 59. The second represents whole seconds passed since the last minute. A single-digit second is formatted without a leading zero.
ss, ss (plus any number of additional "s" specifiers) Represents the seconds as a number from 00 through 59. The second represents whole seconds passed since the last minute. A single-digit second is formatted with a leading zero.
t Represents the first character of the A.M./P.M. designator defined in the current Region property of Control Panel. The A.M. designator is used if the hour in the time being formatted is less than 12; otherwise, the P.M. designator is used.
tt, tt (plus any number of additional "t" specifiers) Represents the A.M./P.M. designator as defined in the current Region property of Control Panel. The A.M. designator is used if the hour in the time being formatted is less than 12; otherwise, the P.M. designator is used.
y Represents the year as at most a two-digit number. If the year has more than two digits, only the two low-order digits appear in the result. If the year has fewer than two digits, the number is formatted without a leading zero.
yy Represents the year as a two-digit number. If the year has more than two digits, only the two low-order digits appear in the result. If the year has fewer than two digits, the number is padded with leading zeroes to achieve two digits.
yyy Represents the year as a three-digit number. If the year has more than three digits, only the three low-order digits appear in the result. If the year has fewer than three digits, the number is padded with leading zeroes to achieve three digits.
Note that for the Thai Buddhist calendar, which can have five-digit years, this format specifier displays all five digits.
yyyy Represents the year as a four-digit number. If the year has more than four digits, only the four low-order digits appear in the result. If the year has fewer than four digits, the number is padded with leading zeroes to achieve four digits.
Note that for the Thai Buddhist calendar, which can have five-digit years, this format specifier renders all five digits
yyyyy (plus any number of additional "y" specifiers) Represents the year as a five-digit number. If the year has more than five digits, only the five low-order digits appear in the result. If the year has fewer than five digits, the number is padded with leading zeroes to achieve five digits.
If there are additional "y" specifiers, the number is padded with as many leading zeroes as necessary to achieve the number of "y" specifiers.
z Represents the signed time zone offset of your system from Greenwich Mean Time (GMT) measured in hours. For example, the offset for a computer in the Pacific Standard Time zone is "-8".
The offset is always displayed with a leading sign. A plus sign (+) indicates hours ahead of GMT and a minus sign (-) indicates hours behind GMT. The offset ranges from ¨C12 through +13. A single-digit offset is formatted without a leading zero. The offset is affected by daylight savings time.
zz Represents the signed time zone offset of your system from Greenwich Mean Time (GMT) measured in hours. For example, the offset for a computer in the Pacific Standard Time zone is "-08".
The offset is always displayed with a leading sign. A plus sign (+) indicates hours ahead of GMT and a minus sign (-) indicates hours behind GMT. The offset ranges from ¨C12 through +13. A single-digit offset is formatted with a leading zero. The offset is affected by daylight savings time.
zzz, zzz (plus any number of additional "z" specifiers) Represents the signed time zone offset of your system from Greenwich Mean Time (GMT) measured in hours and minutes. For example, the offset for a computer in the Pacific Standard Time zone is "-08:00".
The offset is always displayed with a leading sign. A plus sign (+) indicates hours ahead of GMT and a minus sign (-) indicates hours behind GMT. The offset ranges from ¨C12 through +13. A single-digit offset is formatted with a leading zero. The offset is affected by daylight savings time.
: The time separator defined in the current Region property of Control Panel that is used to differentiate hours, minutes, and seconds.
/ The date separator defined in the current Region property of Control Panel that is used to differentiate years, months, and days.
" Quoted string (quotation mark). Displays the literal value of any string between two quotation marks ("). Precede each quotation mark with an escape character (\).
' Quoted string (apostrophe). Displays the literal value of any string between two apostrophe (') characters.
%c Represents the result associated with a custom format specifier "c", when the custom DateTime format string consists solely of that custom format specifier. That is, to use the "d", "f", "F", "h", "m", "s", "t", "y", "z", "H", or "M" custom format specifier by itself, specify "%d", "%f", "%F", "%h", "%m", "%s", "%t", "%y", "%z", "%H", or "%M".
\c The escape character. Displays the character "c" as a literal when that character is preceded by the escape character (\). To insert the backslash character itself in the result string, use two escape characters ("\\").
Any other character Any other character is copied to the result string, and does not affect formatting.

For more information about using a DateTime format specification, see Custom DateTime Format Strings on Microsoft MSDN.

posted @ 2011-04-07 21:20  harrychinese  阅读(759)  评论(0编辑  收藏  举报