A robust starter web application to ease Java webapp development.

Home | Tutorials | Demos | Issues

onSetupBeforeTransaction vs onSetupInTransaction

View: New views
2 Messages — Rating Filter:   Alert me  

onSetupBeforeTransaction vs onSetupInTransaction

by JC Oosthuizen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

I have a question regarding the use of onSetupBeforeTransaction. This will be called before the transaction is created and will therefore not be rolled back when the test is done. I know one can implement the onTearDownAfterTransaction to remove the data added in onSetupBeforeTransaction.

I created a POJO with a unique field, which causes the tests to fail as the object is not properly removed between tests in one test case.

I moved the code from onSetupBeforeTransaction to onSetupInTransaction which solved my problem as the object will be removed when the transaction is rolled back.

Why is the setup done before the transaction and not in the transaction. Doing it in the transaction should give more isolated test cases and should be better.

Regards,

JC Oosthuizen

Re: onSetupBeforeTransaction vs onSetupInTransaction

by Marcello Teodori :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

JC Oosthuizen wrote:
Hi All,

I have a question regarding the use of onSetupBeforeTransaction. This will be called before the transaction is created and will therefore not be rolled back when the test is done. I know one can implement the onTearDownAfterTransaction to remove the data added in onSetupBeforeTransaction.

I created a POJO with a unique field, which causes the tests to fail as the object is not properly removed between tests in one test case.

I moved the code from onSetupBeforeTransaction to onSetupInTransaction which solved my problem as the object will be removed when the transaction is rolled back.

Why is the setup done before the transaction and not in the transaction. Doing it in the transaction should give more isolated test cases and should be better.

Regards,

JC Oosthuizen
I noticed the same in an *ActionTest generated using the appfuse maven plugin.
The test fails as the object saved in onSetupBeforeTransaction gets committed to database, while its correct position should be in onSetupInTransaction as you say.

I've opened an issue:
http://issues.appfuse.org/browse/APF-1082

Marcello
LightInTheBox - Buy quality products at wholesale price