Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I keep my IDatabaseConnection open after setUp/tearDown when extending DBTestCase/DatabaseTestCase?

extending Setup tearDown
0
10 Posted

How can I keep my IDatabaseConnection open after setUp/tearDown when extending DBTestCase/DatabaseTestCase?

0
10

Since DBUnit 2.4.4 there is a new method IDatabaseTester#setOperationListener which allows to set a user defined listener which is invoked on different operations during the test execution. The DBTestCase/DatabaseTestCase classes make use of this new functionality and by default closes the connection after setUp/tearDown operations were executed. Here an example of how to change this behavior so that the connection will not be closed anymore: public class MyTestCase extends DBTestCase{ // Overwrite the method getOperationListener to provide our own operation listener protected IOperationListener getOperationListener() { return new DefaultOperationListener(){ public void operationSetUpFinished( IDatabaseConnection connection) { // Do not invoke the “super” method to avoid that the connection is closed } public void operationTearDownFinished( IDatabaseConnection connection) { // Do not invoke the “super” method to avoid that the connection is closed } }; } } Note that there dbunit provid

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123