How to auto fetch data before test run?

i have data files which fetch data from database.
how to auto fetch data files before the test execution?
as the testing insert new record to database frequently, in order to validate the value from database table before run the next test step. i need extra step to auto fetching data files before execute the test case.

Any idea or suggestion?
Or I should not use data files to get data as data but get them directly in test case, how?

i have same case how to auto fetch data file before running test execution …

I’m bringing this topic up again, any solution for this ?

Step 1. Install Jenkins CI (for Ubuntu)

Step 2. Install MySQL Server (if you don’t have it) and MySQL workbench (optional — if you prefer working with a GUI)

Step 3. Configure MySQL

After installing the MySQL server and workbench, we need to make some changes to the server’s configuration. In the Workbench, looking for where the MySQL configuration file is located:

Open this file and look for the “secure-file-priv” value. You can read more about this value here. In this value, configure the folder for the database to write files to. I set secure-file-priv=“C:\tmp\”. In this folder, I’ll store my *.sql script and the result.csv file that this script will create.

Restart your MySQL server.

Step 4. Create a database and write a script.

I created a “test” database and a “users” table in this database:

In the “C:\tmp\” folder I have a script “script.sql”:

SELECT name,pass INTO OUTFILE ‘C:\tmp\res.csv’
FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘\n’
FROM test.users;
This script turns the DB into a CSV file.

Let’s check it in the command-line:

The execution syntax to connect to the database is

mysql -u <user_name> -p<password_without_space_after_p> <database_name> < “<path_to_sql_script>”
Step 5. Configure Jenkins.

Now switch to Jenkins CI, create a FreeStyle Job and add a Windows batch / Shell build step:

For Windows I created the following script:

del “C:\tmp\res.csv”
“C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql” -u artem -partem test < “C:\tmp\script.sql”
mkdir %BUILD_NUMBER%
copy “C:\tmp\res.csv” “%WORKSPACE%%BUILD_NUMBER%\data.csv”
del “C:\tmp\res.csv”
What this script does:

Removes the result file if it exists in the database, because MySQL cannot overwrite it
Executes the SQL script that will write the result output from the MySQL DB to a CSV file
Creates a folder with the name =BUILD_NUMBER in the Jenkins workspace
Copies the result file to JENKINS_WORKSPACE\BUILD_NUMBER folder and name it.
Removes the result file from C:\tmp
After the execution of this script, we will have a file named data.csv in JENKINS_WORKSPACE\BUILD_NUMBER folder.

You can take this file and run it with JMeter through Jenkins and view results in the Jenkins performance plugin.