JUnit – Sample Maven Project With JDBC
The quality of software should be of a high standard and then only it is liked and used by most people. A good programmer is one who prepares software error-free, JUnit helps us a lot in achieving that. In this article, let us see a MySQL database connecting with Java via JDBC, and the data is checked against JUnit.
Example Maven Project
Maven Project and hence let us look at the dependencies specified in
MySQL connectivity is specified in
# DataSource ds.database-driver=com.mysql.jdbc.Driver ds.url=jdbc:mysql://localhost:3306/geeksforgeeks ds.username=*** #Specify username ds.password=*** #Specify password
Let us assume that there exists a database named “geeksforgeeks ” and it has a table named “worker” the structure of “worker” table is given below
worker table db data:
Here we can get the connection
Let us create the Worker class now
This java program helps us to test the available DB data is helpful for subsequent operations.
- It will help to set the integrity of the project
- By testing in these ways, we can find wrongly entered data and avoid it.
- Quality of software is improved and customizing them helps to prepare error-free software.
This file can be run as a JUnit Test
When expected values and actual DB data values match for all test cases, we can see like below output
In case of any errors, they can be shown as follows
Please Login to comment...