Как правильно тестировать код, который использует специфичные для MySQL запросы?

Я собираю данные и храню эти данные в базе данных MySQL, используя Java. Кроме того, я использую Maven для создания проекта, TestNG в качестве среды тестирования и Spring-Jdbc для доступа к базе данных. Я реализовал уровень DAO, который инкапсулирует доступ к базе данных. Помимо добавления данных с использованием классов DAO, я хочу выполнить несколько запросов, которые объединяют данные и сохраняют результаты в некоторых других таблицах (например, в виде материализованных представлений).

Теперь я хотел бы написать несколько тестовых случаев, которые проверяют, работают ли классы DAO, как они должны. Поэтому я подумал об использовании базы данных в памяти, которая будет заполнена некоторыми тестовыми данными. Поскольку я также использую специфичные для MySQL SQL-запросы для агрегирования данных, у меня возникли некоторые проблемы:

Firstly, I've thought of simply using the embedded-database functionality provided by Spring-Jdbc to instantiate an embedded database. I've decided to use the H2 implementation. There I ran into trouble because of the aggregation queries, which are using MySQL-specific content (e.g. time-manipulation functions like DATE()). Another disadvantage of this approach is that I need to maintain two ddl files - the actual ddl file defining the tables in MySQL (here I define the encoding and add comments to tables and columns, both features are MySQL-specific); and the test ddl file that defines the same tables but without comments etc. since H2 does not support comments. I've found a description for using MySQL as an embedded database which I can use within the test cases (http://literatitech.blogspot.de/2011/04/embedded-mysql-server-for-junit-testing.html). That sounded really promising to me. Unfortunately, it didn't worked: A MissingResourceExcpetion occurred "Resource '5-0-21/Linux-amd64/mysqld' not found". It seems that the driver is not able to find the database daemon on my local machine. But I don't know what I have to look for to find a solution for that issue.

Теперь, я немного застрял, и мне интересно, если бы я должен был создать архитектуру по-другому. У кого-нибудь есть советы, как мне настроить соответствующую систему? Я имею в виду два других варианта:

Instead of using an embedded database, I'll go with a native MySQL instance and setup a database that is only used for the testcases. This options sounds slow. Actually, I might want to setup a CI server later on and I thought that using an embedded database would be more appropriate since the test run faster. I erase all the MySQL-specific stuff out of the SQL queries and use H2 as an embedded database for testing. If this option is the right choice, I would need to find another way to test the SQL queries that aggregates the data into materialized views. Or is there a 3rd option which I don't have in mind?

Буду признателен за любые намеки.

Спасибо, XComp

Ответы на вопрос(2)

Ваш ответ на вопрос