Advanced
Do With - Table, Bullet List or Number List example
GreenPepper supports the expression of rules in table format, bullet list format or number list format. The following examples are equivalent and will yield the same results when executed.
It is important to note that the table and bullet list examples are not executable, since the import com.greenpepper.samples.application.bank and do with bank rules cannot be specified twice in the same page. Even though it is possible to change between the two methods in the same page, you must keep in mind that the tests are executed in the same system under development. So it is not necessary to re-specify the same rule in the page.
Table
import |
com.greenpepper.samples.application.bank |
do with | bank | ||||||
open | checking | account | 12345-67890 | under the name of | Spongebob | Squarepants | |
check | that balance of account | 12345-67890 | is | $0.00 | |||
deposit | $100.00 | in account | 12345-67890 | ||||
check | that balance of account | 12345-67890 | is | $100.00 |
Bullet List
- import
- com.greenpepper.samples.application.bank
- do with bank
- open checking account 12345-67890 under the name of Spongebob _Squarepants
- deposit $100.00 in account 12345-67890
- check that balance of account 12345-67890 is $100.00
Number List
- import
- com.greenpepper.samples.application.bank
- do with bank
- open checking account 12345-67890 under the name of Spongebob _Squarepants
- deposit $100.00 in account 12345-67890
- check that balance of account 12345-67890 is $100.00
Object-Graph Navigation Language (OGNL)
GreenPepper has an extension to supports OGNL expressions. Here are some examples, using the Calculator system:
< , <= , > , >= , and , or | GreenPepper supports these simple mathematical expressions. Use the question mark to specify the position of the value returned by the system. For example, if the expected value should be greater than 15, you would write "? > 15" in the cell. |
---|---|
+ , - , / , * | GreenPepper performs simple operations as a resulting expression. To specify you want to evaluate those operations prior to the comparison, insert an equal sign at the beginning of the operation (ex: =4+1-3). |
rule for | calculator | |||
x | y | sum? | product? | quotient? |
6 | 2 | 8 | 12 | 3 |
7 | 0 | 7 | 0 | error |
40 | 50 | 90 | ? > 100 | |
4 | -5 | ? <= 0 | -20 | ? <= 0 |
3 | 3 | ? < 1 or ? > 4 | ? >= 9 and ? < 12 | "1" |
4 | 2 | =4+2-0 | =2*4 | =4/2 |
To use this extension, you need to specify the fixture factory as com.greenpepper.extensions.ognl.OgnlSupport and add the greenpepper-extensions-ognl-x.x.jar and ognl-x.x.x.jar to the classpath of the SUT.
Information Tag
Information tags
When a document is executable, GreenPepper will try to interpret all the supported forms of the document body.
This could lead to some issues, if we need to insert information as Tables or Bullet lists, for example.
To avoid undesired interpretation of forms, we can use the Information tags.
This tag will force GreenPepper to skip all forms between the Begin Info and End Info tags.
Here is an example:
Begin Info |
This table | shouldn't be | interpreted |
- This bullet list
- shouldn't be
- interpreted either
End Info |
We won't see any coloration of the above table or bullet list after execution of this document.
GreenPepper will restart the interpretation of the document from from this point.
Rule for | Calculator | |
---|---|---|
x | y | sum? |
1 | 2 | 3 |
Useful Information
If the End Info tag is omitted all the body content of the document after the Begin Info tag, will be skipped.
Commented forms
Comment tag
If necessary, we can decide that a test shouldn't be executed. Instead of deleting the test from the document, we can comment it. This will force GreenPepper to skip the test.
The test should be preceded by the tag Comment.
Here are some examples:
Test using the bullet list form.
- Comment
- My bulletlist test to skip
Test using the Table form.
Comment | |
My table | to skip |
We won't see any coloration of the above table or bullet list after execution of this document.
GreenPepper will restart the interpretation of the document from from this point.
Rule for | Calculator | |
---|---|---|
x | y | sum? |
1 | 2 | 3 |
Passing parameter to the fixtures
It's sometimes necessary to pass an argument to a fixture to change it's behavior. The rule to follow for passing these is the following:
- The first cell of the table header is the keyword (Do with, Rule for ....)
- The second cell is the name of the fixture
- then the following cells are managed as followed:
- Odd cells are ignored
- Even cells are parameters values.
These rules allows to create some sentence glue between parameters.
Some practice
Change the mode of the calculator should give access to more functions
Rule for | Calculator | using | Basic | mode | |
---|---|---|---|---|---|
x | y | sum? | product? | quotient? | exp? |
1 | 2 | 3 | 2 | 0.5 | error |
Rule for | Calculator | using | Scientific | mode | |
---|---|---|---|---|---|
x | y | sum? | product? | quotient? | exp? |
1 | 2 | 3 | 2 | 0.5 | 1 |