-4

I am doing a software project, working with database and Java code and in the unit tests, we have to test the selects....I mean, the expectable is that the table that results from the selects, have to correspond with the output in the intellij.....

in a few words, how do I compare a table originated from SQL with output(system.out.println())

Alon
  • 687
  • 1
  • 6
  • 10
  • Possible duplicate of [Best way to test SQL queries](https://stackoverflow.com/questions/754527/best-way-to-test-sql-queries) – UninformedUser Oct 07 '18 at 15:53

1 Answers1

0

You can use an embedded database for that (for example H2).

The workflow would be as follows:

  1. Define a schema for your tables and any initial values.
  2. Start the embedded database at the beginning of your tests and populate it with the defined schema.
  3. Connect to the embedded database from your test code, as you would connect to any database.
  4. Run your SQL against the embedded database.
  5. Do asserts on the results fetched from the database.
  6. Stop the embedded database.

You can find a H2 tutorial here: https://www.tutorialspoint.com/h2_database/h2_database_jdbc_connection.htm