dbunit

Changing Database schemas & unit tests

隐身守侯 提交于 2019-12-12 10:42:07
问题 Before we start I know a fair few people consider tests that hit the database not "unit tests". Maybe "integration tests" would be a better name. Either way developer tests that hit the database. To enable unit-testing I have a developer local database which I clear and the populate with a know set of data at the start of each test using dbUnit. This all works well enough until a table used by the test changes in some way and I have to manually update all the XML datasets. Which is a pain. I

Spring Test DBunit Warning

元气小坏坏 提交于 2019-12-12 08:22:59
问题 I am using spring-test-dbunit and I get a warning in my Unit tests with this message: Code: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/context.xml"}) @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class }) public class TestDB { @Autowired private ICourseService courseService; @Test @DatabaseSetup("sampleData.xml") public

DBunit and dataset column

梦想的初衷 提交于 2019-12-12 05:57:57
问题 I want to try to make unit test with DBUnit but I have a problem with my dataset. Here is my persistence object: @Entity @Table(name = "personnes") public class Personne implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer pk; @Column private String name; } And my dataset: <?xml version='1.0' encoding='UTF-8'?> <dataset> <personnes name="toto" pk="1" /> </dataset> My problem is with the name column, I get this error: org.dbunit.dataset

DbUnit Assertion floating-point numbers

我的梦境 提交于 2019-12-12 00:59:56
问题 I'm testing my DAO layer using DbUnit. I'm prefilling database from XML dataset, doing some actions and then asserting against known result. Assertion.assertEquals(expectedDataSet, actualDataSet); Dataset contains column with floating point number. Then these columns are compared, I get: junit.framework.ComparisonFailure: value (table=OrderLine_T, row=2, col=price) expected:<2.99[]> but was:<2.99[0000009536743]>. The values are equal, but because floating-point numbers cannot be exactly

How to use Oracle Sequence Numbers in DBUnit?

旧时模样 提交于 2019-12-11 04:29:41
问题 How can I used Oracle Sequences to auto-generate primary keys for my tables while exporting data into Oracle using DBUnit ? 回答1: I had the same issue and didn't find any answer. I ended up using a trigger to automatically generate the technical key, as described in this post create table with sequence.nextval in oracle CREATE OR REPLACE TRIGGER ticketSequenceTrigger BEFORE INSERT ON TICKET FOR EACH ROW WHEN (new.id IS null) DECLARE v_id TICKET.id%TYPE; BEGIN SELECT TICKET_ID_SEQ.nextval INTO

Flyway/Liquibase for Database Structure and DBUnit for Database Inserts?

£可爱£侵袭症+ 提交于 2019-12-10 17:47:18
问题 I have the following scenario for my application: 1 Production Server 1 Test Server n Development Computers For database migration we use Hibernate Schema Update for the Schema and DBUnit for filling in alle the production data (on all servers/computers). When the schema update is done I generate a new DTD File for the new schema, so I can do a fresh import of the DBUnit XML. The application updates the database at startup with the XML file (only on development and test servers/computers!) Of

Why should I avoid using DbUnit to test MySQL?

空扰寡人 提交于 2019-12-10 13:17:59
问题 I have recently become involved with some TDD using PHPUnit. I have to test a database-driven app, and read about the DbUnit extension, which I was planning to research and implement over the coming weeks. However, I have come across this presentation by the man himself - Sebastian Bergmann - He has a slide entitled 'Avoid testing against MySQL if you can', which has cast some doubts upon my escapade. Can someone explain the reasons why I should not test against MySQL? Thanks 回答1: Two reasons

DBUnit: how to change a property value correctly?

荒凉一梦 提交于 2019-12-10 11:23:59
问题 I have the problem with DBUnit (V2.5.3) that I want to set the property FEATURE_ALLOW_EMPTY_FIELDS to true but DBUnit ignores this setting. My code to set the property is: DatabaseConfig dbCfg = null; try { dbCfg = dbTester.getConnection().getConfig(); dbCfg.setProperty(DatabaseConfig.FEATURE_ALLOW_EMPTY_FIELDS, Boolean.TRUE); System.out.println("getCfg -> " + dbTester.getConnection().getConfig().getProperty(DatabaseConfig.FEATURE_ALLOW_EMPTY_FIELDS)); System.out.println("dbCfg -> " + dbCfg

Reset sequence in DBUnit?

空扰寡人 提交于 2019-12-09 11:41:05
问题 I want to reset the Database AND sequences after each test in Java+DBUnit/. I've seen this question but doesn't have the code solution I am struggling to get. How to use Oracle Sequence Numbers in DBUnit? 回答1: I've found the answer, it was in the Official Documentation. It was as easy as in the dataset you are using to prepare the database, add a reset_sequences attribute with a list of the ones you want to reset. <?xml version='1.0' encoding='UTF-8'?> <dataset reset_sequences="emp_seq, dept

JAXBException: “package” doesnt contain ObjectFactory.class or jaxb.index

眉间皱痕 提交于 2019-12-07 04:49:39
问题 I have been playing with JAXB / MOXy a lot lately, and it works great on all my tests and example codes . I exclusively using binding files, that's why I'm using MOXy. Please note that in all my examples, I'm NEVER using an ObjectFactory nor a jaxb.index, and it works GREAT . When I get back to my business, I get a nasty JAXB Exception saying that my package does not contain an ObjectFactory or jaxb.index. My project also invovles Spring and Hibernate, JUnit and DBUnit. Here is some sample