[Qt-jambi-interest] Strange Behavior whit Junit4 test suites and QJDBC
José Arcángel Salazar Delgado
arcangel.salazar at gmail.com
Tue Jul 15 18:30:23 CEST 2008
Eskil Abrahamsen Blomfeldt escribió:
> José Arcángel Salazar Delgado wrote:
>> The ClienteTest runs fine, but ProductoTest is broken. This is the
>> error:
>> QSqlDatabasePrivate::removeDatabase: connection
>> 'qt_sql_default_connection' is still in use, all queries will cease
>> to work.
>> QSqlDatabase: QJDBC driver not loaded
>> QSqlDatabase: available drivers:
>> Driver not loaded Driver not loaded
>>
>
> Hi, José.
>
> Does the ProductoTest work if you exclude the ClienteTest class?
>
> If each of the tests in your suite is run in the same process, then I
> imagine you will have some problems, as you are initializing and
> disposing your application instance at the beginning and end of each
> test. There should in principle only be a single application instance
> for the duration of the application.
>
> Is there any way to write setup code that is only run before and after
> the entire suite (not before and after each class)? If so, could you
> try moving the QCoreApplication initialization and tear-down code to
> these methods and see if that solves the problem?
>
Thanks, that give me and Idea. The solution is this:
@BeforeClass
public static void setUpBeforeClass() throws Exception {
String[] args = new String[0];
if(QCoreApplication.instance() ==null){
QCoreApplication.initialize(args);
QJdbc.initialize();
try {
Class.forName("org.h2.Driver");
}
catch (Exception ex) {
System.err.println(ex);
}
}
QSqlDatabase db = QSqlDatabase.addDatabase(QJdbc.ID);
db.setDatabaseName("jdbc:h2:databases/clientes/clientes");
db.setUserName("sa");
db.setPassword("");
if (db.open()) {
System.out.println("Conexión realizada!");
} else {
System.err.println("Conexión fallida!");
System.err.println(db.lastError().text());
}
return;
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
QSqlDatabase.database().close();
}
This is the only way that I found the fix the problem, because Junit4
doesn´t support beforeSuit or afterSuite test Tags or anything similar.
>
>> P.D: Is there any plan to port the QTest framework to Jambi?
>>
>
>
> No, there are no plans for that.
>
> -- Eskil
>
Thanks for the help.
More information about the Qt-jambi-interest
mailing list