Database Implementation
In this section, the Database concept will be implemented. It is responsible for preparing the persistent state of the application as a prerequisite for executing the successful login test scenario in Probato. In Probato, Database is used to define state, not to execute test logic. SQL or NoSQL scripts are declared explicitly and executed automatically before scenarios run.
Creating the SQL files
- In the
src/test/resources/sqldirectory, create a folder namedinit. - In the
src/test/resources/sqldirectory, create another folder nameduser. - Inside
src/test/resources/sql/init, create the fileinit.sql. - Inside
src/test/resources/sql/user, create the fileinsert-user.sql.
Global initialization script
The init.sql script is used to prepare the global state of the feature and is executed before all Scripts in the Suite.
Scenario data script
The insert-user.sql script is used to prepare the scenario-specific state, inserting the users required for the login test.
INSERT INTO testano_app.users
(id, "name", email, "password", gender, active)
VALUES
('a02b03e6-c462-4980-9997-c1203a094c9d'::uuid, 'User 01', 'user01@probato.org', '$2a$10$Kml4nk3ADhnWrJg0GkStVeTJoslDBir/Fgyw2gkLR0FukujfIxZQ2', 'MALE', true);
INSERT INTO testano_app.users
(id, "name", email, "password", gender, active)
VALUES
('bd84a2c8-d315-40ea-80aa-1841254b20c9'::uuid, 'User 02', 'user02@probato.org', '$2a$10$oHZ7er1/2/xKjgOq0znXnOPcvoOXpX.in6XO/4mf2xf5ZV7OMyvq6', 'MALE', true);
INSERT INTO testano_app.users
(id, "name", email, "password", gender, active)
VALUES
('b86a08ac-2ee8-42c7-a46f-c589b1d26503'::uuid, 'User 03', 'user03@probato.org', '$2a$10$81pSkjzZTqgn3/nU5DzxVemmr0rjJ7NHtK/UiGhzomEwTyHZgFliC', 'MALE', true);
Updating the Script class
The Script can declare scenario-specific state through the @SQL annotation.
At this point:
- The Script declares which specific state it requires
- The Database is prepared automatically before execution
- The Procedure remains focused only on business logic
Updating the Suite class
The Suite can declare global feature state, applied before all Scripts.
| UC01_Login.java | |
|---|---|
This ensures that:
- The global state is prepared only once
- Each Script applies only its specific state
- There is no coupling between state and test logic
Final Checklist
Before proceeding, make sure that:
- ✅ The SQL files were created correctly.
- ✅ The
probatodatasource is configured inconfiguration.yml. - ✅ The SQL scripts are executed before test execution.
- ✅ The scenario runs with a predictable and controlled state.
With the Database implementation completed, automation becomes reproducible, predictable, and reliable.