Hi guys,

If I’m not wrong only few databases consider DDL as a transactional
statement (so you can rollback it). Maybe for H2 they’re not. You’d better
check the documentation!

So your best alternative is cleaning the database up after each test. You
can do it through jUnit @After annotation or creating your own jUnit Rule.

What do you think?
On Thu, 18 Oct 2018 at 13:38 <[email protected]> wrote:

> Let's take a look from another view. Consider you want to test some db
> behavior such as insert, create, update, delete, and so one in test.
> Expectation is to have same db setup for all test with few default tables
> and data init.  So what happen in 1 test should not affect another test.
> Truncating data is one thing, i believe that can be handled somehow, but
> what about created or deleted tables? How to rollback after each test
> created table or put back deleted table ?
>
> Regarding to @Transactional: Docs is saying: "If your test is
> @Transactional, it rolls back the transaction at the end of each test
> method by default."  (Taken from
> https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
> *). *
>
> Dne čtvrtek 18. října 2018 16:16:32 UTC+2 Lukas Eder napsal(a):
>>
>> Hello,
>>
>> That doesn't sound like how spring works. A @Transactional method will
>> always commit by default, or rollback on exception. But there is perhaps
>> some Spring/JUnit feature that extends JUnit in the desired way?
>>
>> I don't know spring well enough. Perhaps you can get an answer on Stack
>> Overflow:
>> https://stackoverflow.com
>>
>> Thanks,
>> Lukas
>>
>> On Thu, Oct 18, 2018 at 4:03 PM <[email protected]> wrote:
>>
>>> Hi all,
>>>
>>> We ran into problem in our integrationTest. We are using Spring Boot +
>>> Postgre +JPA(hibernate) + Jooq. Besides other things (like queries and so
>>> on) we are using DSLContext obj.(dsl) for creating some dynamic tables. Now
>>> our issue lays on integration Tests.
>>>
>>> For tests, we are using H2 db.
>>>
>>> All int. test extends  this class def:
>>>
>>> ContextConfiguration
>>> @SpringBootTest(webEnvironment = RANDOM_PORT)
>>> @ActiveProfiles("test")
>>> @Transactional
>>> // We tried also @Rollback annotation doesn't work either.
>>> class IntTestWithContext extends Specification {
>>> .....
>>> .....
>>> }
>>>
>>> We have test, where we are trying to validate, that in some cases, table
>>> is created and for other actions is deleted.
>>> My understanding of @Transactional was, that after each test, all
>>> changes should be rollbacked to previous state. We had also annotation
>>> @Rollback for that purpose, but it doesn't worked either. Issue is when we
>>> run in our test: dsl.dropTableIfExists('DYNAMIC_TABLE_1').execute(); This
>>> script however triggers commit, which actually push all changes made in
>>> test into DB. When this test ends, then all what was commited is stored in
>>> h2 Db and make other test failing. My question is pretty straight forward.
>>> What can we do with this.
>>> Expected behavior is : using jooq in test with all changes rollbacked in
>>> the end of the test.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "jOOQ User Group" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>
>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Rafael Ponte
TriadWorks | Formação Java
http://cursos.triadworks.com.br

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to