-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
95 lines (72 loc) · 3.55 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
BDD vs TDD
https://cucumber.io/blog/bdd/bdd-vs-tdd/
feature files -> Step definition file -> runner files
Example Mapping:
is Mapping user story with several examples that lead to identification of business rules
User Story -> Example -> Business Rules
this will result in "feature files"
Feature files
written in Gherkin Domain specific language Gherkin DSL
Feature: Menu Management
Scenario: Add a menu item
Given … #condition
When … #action
Then … #result
you will notice that step definition file that variables in feature files are converted into parameters of the methods
these variables are called cucumber variables
whenever running a definition file and it encounters a pending exception, it stops running that entire files
the @CucumberOptions is depreciated so if you want to use cucumber with JUnit5 use
@Suite
@SelectClasspathResource("com/rmdaw/cucumber/features")
//@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.rmdaw.cucumber")
//@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
you can save the configurations in junit-platform.properties
cucumber.publish.quiet=true
cucumber.plugin=pretty,...
cucumber.glue=com.rmdaw.cucumber,...
________________________________________________
@Given("I have a menu item with name {string} and price {int}")
to
@Given("I have a menu item with name {string} and price ([1-9]+)")
the () is called capture group
IMPORTANT to use regexp in stepdefinitions wrap the string inside given/when/Then
with "/ ___ /" or "^ _____ $"
inside is REGULAR Expression,
SUMMARY OF REGULAR EXPRESSIONS
+ is a Quantifier
+ 1-*
* 0-*
? 0-1
{x} x=exact quantity
^ anything but e.g. [^Z] Zebra=false, zebra=true, bra=true
@Given("I have a menu item with name {string} and price ([\\d]+)")
\d d: single digit 0-9
\w single word char: a-Z 0-9 _
\s whitespace char: ' ', tabs, endofline
@Given("I have a menu item with name \"([^\"])\" and price ([\\d]+)")
\"([^\"]+)\" is "([^"])+" which is anything but " 1-*
________________________________________________
Tags help filter tests
mvn test -Dgroups="SmokeTest,NightlyBuildTest"
or
mvn verify -Dgroups="SmokeTest,NightlyBuildTest"
________________________________________________
Background runs before every scenario, its like beforeach but actually documented and shown to everyone
Note how each scenario has a new RestaurantMenu object, showing how scenarios behave like JUnit tests
each are independent and have fresh copy of parent object and new memory
Note in Spring here that scenarios behave like JUnit test, they are ran independent though they all
rely on the spring context that has a state, LocalDB is in memory DB that is persisted
throughout the scenario because its tied to spring application context, while justCount
is not thus each scenario sees a new justCount. meaning different objects of addingEventSteps
were used to test each scenario differently
________________________________________________
Hooks @Before @After behave like in JUnit setup teardown, it applies to the entire scenario
its useful for clearing cache or terminating connections
use feature background whenever other non dev team members need to know about it
Background steps execute after the before hooks.
________________________________________________
checkout the plugins added to the properties file
mvn surefire-report:report can be used too
________________________________________________
note that int and double share values
if doing financial calculations use bigInteger, and BigDecimal