java - Rollback auto-generated table values during unit tests -


my unit test config is: junit, dbunit, spring.

in spring context have embedded database -

<jdbc:embedded-database id="datasourcespied">     <jdbc:script location="classpath:test_ddl.sql"/> </jdbc:embedded-database> 

my unit tests come following class-level annotations:

@contextconfiguration(locations = "classpath:/test-context.xml") @runwith(springjunit4classrunner.class) @transactional @testexecutionlisteners({dependencyinjectiontestexecutionlistener.class,         transactiondbunittestexecutionlistener.class,         dbunittestexecutionlistener.class}) 

my test schema has following fragments:

create table test(   id  bigint generated default identity,   name  varchar(255) not null,   ... ); 

the @transactional annotation rollbacks changes make during single unit test method but doesn't clear id values! auto-generated id value doesn't reset, unit tests have dependency on order in run!

how reset auto-generated db fields of hsqldb in spring during tests?


perhaps trucate command help?

in example, autogenerated identity can modified.

 alter table test alter column id restart 0 

see guide:

http://www.hsqldb.org/doc/2.0/guide/databaseobjects-chapt.html#dbc_table_manupulation


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -