Skip to content

Commit 67843e8

Browse files
committed
Updated documentation to add Background and Cleanup
1 parent 93e57dd commit 67843e8

35 files changed

+2408
-162
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ to call a parametrized test method. The scenarios can be used in user documenta
2525
For domains which have two-dimensional objects, the tabular format can be much easier
2626
to comprehend. (See the tic-tac-toe example.)
2727

28+
You can think of a Gherkin feature file as representing the logical portion of the test (ala the logical and physical views of a database).
29+
2830
### introductory Example
2931

3032
Here are a few introductory examples. You can view the `examples.feature` file in the main test directory

details.md

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ generated.
315315
## Include
316316

317317
You can include another file in a feature file. e generated. If the file is a `.csv` file, it will be converted to a table.
318-
319318
```
320319
Feature: Include
321320
@@ -331,14 +330,11 @@ Given a string in base directory
331330
Include 'string.inc'
332331
"""
333332
```
334-
335333
You can include any text, including `Data` statements (useful for reusing common data layouts).
336334
If you surround the filename with single quotes `'string.inc'`, the file will be searched for in the `Configuration` value:
337-
338335
```
339336
public static final String featureSubDirectory = "src/test/java/";
340337
```
341-
342338
The included file might have a `Feature` statement in it. If it does, a warning will begenerated.
343339

344340
## Tables
@@ -505,93 +501,95 @@ Scenario: Here are string options
505501
Three line
506502
Four line
507503
"""
508-
509504
```
510505

506+
## Background and Cleanup
507+
508+
You can add a `Background `and a `Cleanup `to a feature file. All steps in the `Background `will be run when the scenario starts. All steps in the `Cleanup `will be run when the scenario ends. `Background `and `Cleanup `use the same glue context as the scenario in which they run
511509
```
510+
Feature: Background
511+
512+
Background:
513+
Given Background function sets a value
514+
| Background Here |
515+
516+
Cleanup::
517+
Given value for cleanup should be set to
518+
| Cleanup Here |
512519
520+
Scenario: Should have Background and Cleanup
521+
Given a regular function
522+
Then background should set value to
523+
| Background Here |
524+
And set a value for cleanup
525+
| Cleanup Here |
513526
527+
Scenario: Should also have Background and Cleanup
528+
Given a regular function
529+
Then background should set value to
530+
| Background Here |
531+
And set a value for cleanup
532+
| Cleanup Here |
514533
```
515534

535+
## JSON
536+
537+
Four methods are added to the string version of the data class. These methods convert an object to and from JSON and convert a table to and from JSON. They were added since JSON is a popular way to represent attributes. Methods to and from YAML or XML or some other format can be added.
538+
516539
## Define
517540

518541
There is one more facet that might have
519542
some use, depending on your context. With a `define`, you specify
520543
the value of a constant once, e.g.
521-
522544
```
523545
Define
524546
| Name | Value | Notes |
525547
| HIGH_VALUE | 100 | Highest allowed input |
526548
| LOW_VALUE | 1 | Lowest allowed input |
527549
```
528-
529-
```
530-
531-
```
532-
533550
Whereever you use these tokens, they will be replaced by the value. For example:
534-
535551
```
536552
Given this data:
537553
| ID | Value |
538554
| A | HIGH_DATA |
539555
| B | LOW_DATA |
540556
```
541-
542557
will be treated as:
543558

559+
```
544560
Given this data:
545561
| ID | Value |
546562
| 1 | 100 |
547563
| B | 1 |
548-
564+
```
549565
This is useful if the Define terms are meaningful to someone reading
550566
the feature file.
551567

552568
### Calculated Values
553569

554570
You can use an expression in the replacement, such as:
555-
556571
```
557572
| Name | Value | Notes |
558573
| AVERAGE_VALUE | (LOW_DATA +HIGH_DATA)/2 |
559574
```
560-
561575
In this case, the computation will be passed, not the result of the computation:
562-
563576
```
564577
Given this data:
565578
| ID | Value |
566579
| A | HIGH_DATA |
567580
| B | LOW_DATA |
568581
| C | AVERAGE_VALUE |
569582
```
570-
571583
will be treated as:
572-
573584
```
574585
Given this data:
575586
| ID | Value |
576587
| 1 | 100 |
577588
| B | 1 |
578589
| C | (1 + 100)/2 |
579590
```
580-
581591
You need to create (or find somewhere) a class that computes the result
582592
Of this calculation. Suppose it was called ComputeInt with a string constructor. The Data statement would have Datatype ComputeInt for this
583593
Field.
584594

585595
For Java, you can check out the ScriptEngineManager and ScriptEngine classes from the javax.script package:
586-
587-
588-
589-
590-
591-
592-
593-
594-
595-
596-
597-

gherkinexecutor.Feature_Examples

Lines changed: 0 additions & 57 deletions
This file was deleted.

gherkinexecutor.Feature_Examplesfeature.txt

Lines changed: 0 additions & 57 deletions
This file was deleted.

gherkinexecutor.Feature_Simple_Testfeature.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

log.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

miscellaneous.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
To Do and Miscellaneous Notes
2+
3+
4+
5+
## Benefits
6+
7+
- Works with existing Xunit frameworks. A Scenario is one XUnit test.
8+
9+
- Little configuration - Where are the feature files (default is JetBrains) and where to put the test
10+
11+
- Adaptable - redo Translate to your liking, could get feature files from elsewhere, could translate and execute feature files in a single step, etc.
12+
13+
- Source code is all there
14+
15+
- Separates logical tests from implementation in code
16+
17+
- Promotes writing tests. Tabular notes on a blackboard can easiliy convert into a test.
18+
19+
- Promotes DDD. Domain types show up in the feature file.
20+
21+
- Developers can create the feature file in lieu of a parameterized unit test. Sometimes it's easier to scan a table to see missing conditions.
22+
23+
### Disadvantages
24+
25+
- Have to run Translate after changing feature file. Could incorporate this into IDE
26+
27+
-
28+
29+
It is easier to translate data to what is required than it is to duplicate logic
30+
31+
32+
33+
Add an email example
34+
35+
Add a Robot example
36+
37+
38+
39+

0 commit comments

Comments
 (0)