lundi 2 septembre 2019

How can I use different sql files with Data for different test files?

I have a project with a big data.sql file where we have nearly 2000 lines of insert statements. This is very bad. It is not nice to work with this file. Most tests rely on just 5-20 of those insert statements. This is why I want to change the testing so that in every (test) class we can load a different sql file. How is this possible?

  • I removed the data.sql file and now it starts up with no data at all. Fine so far...
  • I have created a small.sql file with just a couple of insert's. I have inserted it into my test file with the following code, but I get only errors:
    @Before
    public void beforeTest() throws SQLException {

        Connection connection = DriverManager.getConnection(
                "jdbc:h2:mem:PROJECT;MVCC=true;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'classpath:init-h2.sql';MODE=Oracle;DB_CLOSE_ON_EXIT=FALSE", "sa", "");

        Reader data = new StringReader("small.sql");
    }

org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "SMALL[*].SQL "; expected "DELETE, DROP, DECLARE, DEALLOCATE, {"; SQL statement:
small.sql [42001-197]

This is a spring boot application with Java 8.

Aucun commentaire:

Enregistrer un commentaire