Skip to content

Commit 209f202

Browse files
committed
docs: complete README instructions
- Add steps for test configuration
1 parent acdb7e8 commit 209f202

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,40 @@ The JSON representation of an IOU that you'll get in responses or provide in the
267267
### Exercise 3
268268

269269
1. Create an `ious` package inside the `rest-api/src/test/java/com/cbfacademy/springbootexercise` package
270-
2. Download the [test suite](https://gist.github.com/cbfacademy-admin/be990e8da45fca196513f35f86ed3f52) and copy to the test ious package as IOUControllerTest.java
271-
3. Run the tests with `./mvnw --projects rest-api clean test`
272-
4. Examine the results. Do any tests fail? If so, what reasons are given? Modify your code so all tests pass
273-
5. Commit your changes
270+
2. Download the [test suite](https://gist.github.com/cbfacademy-admin/be990e8da45fca196513f35f86ed3f52) and copy to the test `ious` package as `IOUControllerTest.java`
271+
3. **Configure H2 database for testing**: Add the H2 database dependency to your `rest-api/pom.xml` file. Insert this dependency in the `<dependencies>` section:
272+
273+
```xml
274+
<dependency>
275+
<groupId>com.h2database</groupId>
276+
<artifactId>h2</artifactId>
277+
<scope>test</scope>
278+
</dependency>
279+
```
280+
281+
4. **Create test configuration**: Create a new directory `rest-api/src/test/resources` and add an `application.properties` file with the following content:
282+
283+
```properties
284+
# Test configuration using H2 in-memory database
285+
spring.datasource.url=jdbc:h2:mem:testdb
286+
spring.datasource.driverClassName=org.h2.Driver
287+
spring.datasource.username=sa
288+
spring.datasource.password=
289+
290+
# H2 Console for debugging (optional)
291+
spring.h2.console.enabled=true
292+
293+
# JPA/Hibernate configuration for H2
294+
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
295+
spring.jpa.hibernate.ddl-auto=create-drop
296+
spring.jpa.show-sql=true
297+
```
298+
299+
5. Run the tests with `./mvnw --projects rest-api clean test`
300+
6. Examine the results. Do any tests fail? If so, what reasons are given? Modify your code so all tests pass
301+
7. Commit your changes
302+
303+
> :bulb: **Note:** The H2 configuration ensures tests use an in-memory database for speed and isolation, while your production application continues to use MySQL. The `create-drop` setting means the database schema is recreated for each test run, ensuring clean test conditions.
274304
275305
### Exercise 4
276306

0 commit comments

Comments
 (0)