dbunit

How to insert line breaks dbunit dataset.

How to insert line break in dbunit dataset? Like this: <user id="1" story="first line second line third line"/> If I do it in this way field story in db appears divided by spaces only but I need a line break. ...

Date relative to current in the DBUnit dataset

I'm wondering if there is any way to specify for example tomorrow as date in the DBUnit XML dataset. Sometimes code logic is different for dates in future and dates in the past and I want to test both cases. For sure I can specify something like the 5th of November 2239 and be sure that test will work till this date but are there more el...

Putting BigDecimal data into HSQLDB test database using DbUnit

Hi everyone, I'm using Hibernate JPA in my backend. I am writing a unit test using JUnit and DBUnit to insert a set of data into an in-memory HSQL database. My dataset contains: <order_line order_line_id="1" quantity="2" discount_price="0.3"/> Which maps to an OrderLine Java object where the discount_price column is defined as: @Co...

using spring, hibernate and scala, is there a better way to load test data than dbunit?

Here are some things I really dislike about dbunit: 1) You cannot specify the exact ordering the inserts because dbunit likes to group your inserts by table name, and not by the order you define them in the XML file. This is a problem when you have records depending on other records in other tables, so you have to disable foreign key co...

Many small dbunit data sets or one large one?

Spreading test data across multiple small data sets seems to me to create a maintenance headache whenever the schema is tweaked. Anybody see a problem with create a single larger test data set? By "larger" I'm still only talk about a couple hundred records in total. ...

Best way to create / drop a database before / after integration testing on a Maven/Junit/DBUnit project?

I've seen some people use the maven-sql-plugin to do this. But it seems like a task that is better suited for DBUnit....perhaps at the beginning of an entire test suite. What's the best practice here? ...

Is automatic rollback of DAO integration tests with Spring Test a good practice?

If I were to annotate my DAO integration test methods with @Transactional, Spring Test will happily rollback any changes to the database after each test methods completes. These seems extremely convenient, because I can load the test data once with a @BeforeClass method and all clean up is handled for me. But I question whether this is...

How to load DBUnit test data once per case with Spring Test

Spring Test helpfully rolls back any changes made to the database within a test method. This means that it is not necessary to take the time to delete/reload the test data before each test method. But if you use the @BeforeClass Junit annotation, then that forces the data loader to be static. A question that is explored here: http:...

Path to XML DTD for DBUnit in multi-module Java/Maven project?

I have a multi-module maven project. Within the persist module I have a number of XML files data files that reference a DTD: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE myapp-data SYSTEM "myapp-data.dtd" > <dataset> .....omitted for brevity.... </dataset> The DTD is stored in the same directory with the XML files and even...

Question about DBUNIT and Junit

Hi All, I have a database process written in PL/SQL that i would like to test using DBUNIT. The pl/sql program processes data from one table and generates new data into a new table. In some cases it also updates fields on the original table. I am a bit confused in how i can use dbunit to test this. Reading up on it, it looks like i h...

using AbstractTransactionalDataSourceSpringContextTests with Hibernate & DbUnit - inserted data not found

All, I'm attempting to write a unit test for a Dao that uses Hibernate. I'm also using Spring, so I'm trying to extend AbstractTransactionalDataSourceSpringContextTests and also use DBUnit to insert data into the database before each test in the onSetUpInTransaction method. From my logs, I can see that DbUnit is able to successfull...

Loading datasets in consecutive tests fails with "closed session"

Hi all, I have 2 test classes, both annotated with the unitils annotation @DataSet("/dbunit-dataset.xml") The target database is an HSQLDB, which is initiated in an abstract superclass method annotated with the testng annotation: @BeforeClass When the testrunner (Maven Surefire) arrives at the 2nd test, the database is correctly i...

dbunit assertion not throwing failure properly

Hi, Following is a test case which tests the working of org.dbunit.Assertion.assertEquals(ITable a, ITable b) @Test public void testAssertion() { try { //Creating actual table with 2 columns DefaultTable actual = new DefaultTable("table_name", new Column[] { new Column("col1", DataType.INTEGER), ...

PHPUnit and DBUnit - getting started

Does anyone have a link to a good, working tutorial or book on how to get started with adding the DBUnit layer to my PHPUNit tests? I've tried following the code in protected function getDatabaseTester() { $pdo = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass'); $connection = new PHPUnit_Extensions_Database_DB_Defau...

dbunit retrieve max(id) of a table

I am using dbunit to insert some data into table. Is there a way I can tell DBUnit to use the max(id) as the primary key. or is there any other way in dbunit to insert rows without me having to enter the primary key Thanks in advance ...

OutOfMemoryError: Trying to optimise Maven multi-module unit tests using HSQLDB, DBUnit, unitils, Hibernate, Spring

I have a big multi-module Maven project with thousands of tests. Each test loads DAOs, services, etc using the SpringApplicationContext annotation. My unitils configuration looks like this: database.driverClassName=org.hsqldb.jdbcDriver database.url=jdbc:hsqldb:file:mytestdb database.schemaNames=PUBLIC database.userName=sa database.pass...

How to revert the database back to the initial state using dbUnit?

I am new to automated testing and dbUnit. So I would appreciate your advice. I am going to create a test suite, that will run the following way: create an in-memory H2 database run DDL scripts to create tables run dbUnit to insert initial data (let's call it STATE0) that will be used by all tests. run tests Till there it looks nice ...

How can I make dbUnit or hibernate stop subtracting an hour from my dates?

So, I have an XML file I am using with dbUnit as a data source, and it has some dates in it. The date in the file is like so: "2010-02-04", but once it gets loaded and I access it to print or compare in tests, it thinks the date is "2010-02-03 23:00". I'm guessing this has to do with EDT/EST, but I'm not sure how I can force dbUnit (or...

JPA - How to truncate tables between unit tests

I want to cleanup the database after every test case without rolling back the transaction. I have tried DBUnit's DatabaseOperation.DELETE_ALL, but it does not work if a deletion violates a foreign key constraint. I know that I can disable foreign key checks, but that would also disable the checks for the tests (which I want to prevent). ...

DbUnit - Warning: AbstractTableMetaData

Hello! I am using DbUnit in the latest version 2.4.8 and I get many warnings in my Unit tests with this message: WARN : org.dbunit.dataset.AbstractTableMetaData - Potential problem found: The configured data type factory 'class org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems with the current databas...