You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: memex/CONTRIBUTING.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,6 +54,40 @@ To ensure test data isolation and prevent unintended side effects, vehicle inspe
54
54
55
55
These properties can be adjusted in `src/test/resources/application-test.properties` if necessary for specific testing needs, but ensure they define a sensible range and that all tests strictly adhere to operating only within the specified `testid` boundaries.
56
56
57
+
## Adding a New Test
58
+
59
+
To add a new Cucumber test, follow these general steps:
60
+
61
+
1.**Define Scenarios in a `.feature` file**:
62
+
* Locate an existing relevant `.feature` file in `src/test/resources/features/` (e.g., `inspections.rest.crud.feature`, `inspections.kafka.feature`) or create a new one if testing a new feature area or interaction type.
63
+
* Write your test scenarios using Gherkin syntax (Given/When/Then). Clearly describe the preconditions, actions to be performed, and expected outcomes.
64
+
* Use tags (`@tagname`) to categorize your scenarios or features (e.g., `@restapi`, `@kafka`, `@sunny_day`).
65
+
66
+
2.**Implement Step Definitions**:
67
+
* For each Gherkin step in your scenario, you'll need a corresponding Java method in a step definition class. These classes are organized by concern within `src/test/java/com/johnlpage/memex/cucumber/steps/`:
68
+
*`MongoPreConditionSteps.java`: For steps setting up or verifying database state (`@Given`).
69
+
*`RestApiSteps.java`: For steps interacting with the REST API (`@When`, `@Then`).
70
+
*`TimeManagementSteps.java`: For steps related to time (capturing timestamps, waiting).
71
+
*`KafkaConsumerSteps.java`: For steps interacting with Kafka consumers/topics.
72
+
* If your new steps cover a distinct area of functionality that doesn't fit well into any of the existing `Steps` classes above (e.g., interacting with a new external service, or a completely different domain of application logic), it's appropriate to create a new Java class for these step definitions within the `src/test/java/com/johnlpage/memex/cucumber/steps/` package. Ensure it follows the same patterns for dependency injection (e.g., `@Autowired` fields) and Spring configuration if needed.
73
+
***Reuse existing steps**: Before writing new step definition methods, check if existing ones in the relevant files can be reused.
74
+
***Create new steps**: If a step is new, add a public method annotated with `@Given`, `@When`, or `@Then` and a regex matching your Gherkin step to the appropriate class:
75
+
***Data Setup (`@Given` in `MongoPreConditionSteps.java`)**:
76
+
77
+
Use `MongoTemplate` for direct database interaction.
78
+
Crucially, ensure any `testid` values for `VehicleInspection` data are validated using the injected `VehicleInspectionIdRangeValidator` to adhere to the configured range in `application-test.properties`.
79
+
***API Interaction (`@When`/`@Then` in `RestApiSteps.java`)**:
80
+
81
+
Use Rest Assured to build, send HTTP requests, and validate responses.
82
+
Utilize the injected `MacrosRegister` if your Gherkin step includes URL placeholders (e.g., `<timestamp>`) that need to be dynamically replaced.
83
+
84
+
3.**Run Your Test**:
85
+
* Execute the tests (e.g., using `mvn clean verify` or by running the specific feature/scenario from your IDE).
86
+
* Ensure your new test passes and doesn't break existing tests.
87
+
88
+
4.**Check Code Coverage**:
89
+
* After your tests pass, review the JaCoCo code coverage report (see "Code Coverage" section below) to ensure your changes are adequately covered.
90
+
57
91
### Code Coverage
58
92
59
93
We use **JaCoCo** to measure code coverage by our tests.
0 commit comments