Announcement Announcement Module
No announcement yet.
Unit testing: which solution? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unit testing: which solution?

    Hi there,
    I'm writing to you since i would like to find an easy and nice solution for my unit tests.

    OK first my environment: i'm working under IntelliJ Idea, using Maven 2, Hibernate 3.1.3, Spring 1.2.9 and Andromda 3.2 for the generation of DAO, Entity Beans, VO, Hibernate mappings, Spring configuration files and so on.

    Then, my goal: i want to unit test my Spring services and my DAO in a data-driven way: i could also be interested in the behaviour-driven way, but i have a deadline in one month and i am not sure it would be relevant. At least for the moment, data-driven is ok.

    I'd like those tests to be environment-independent : we will use MySQL 5 for production, but for unit testing, i want an other solution, something like HSQL in-memory or in-process, or using DbUnit, or ... ? What i would prefer not to occur: having some database written somewhere: we are 2 developers, i'm not alone, so every change on the database schema (this occurs frequently) must not be a pain in the ass everytime. As well as starting manually a database everytime we test it

    My tests must be runnable via my IDE (Junit embedded in IntelliJ Idea... or just unit tests even if not Junit), and via Maven test goal.

    Also, i have some test data: so i need to have them loaded or pre-loaded in an easy way for each test. I don't know yet if i want the changes to be rolled-back (rollbacked? my english iz not vairi goude) but i guess it might be useful. Might

    Finally i want someting easy to implement and install : we have one month left and i barely have time to waste on this. We were even thinking about giving up unit tests for the moment and implement them later (no please don't beat me). Besides, this must be easily "portable": for example, i implement/install everything, and then i commit on my Subversion, and my colleague can use this directly, and it would work straight on.

    So here we are. I'm quiet opened to everything and i'm sure i don't know all the solutions, so i'm listening to you.
    I probably can't get a perfect solution... but we never know...


    PS: here are some solutions i have thought about:
    - HSQL in-process (.script file) + JUnit : but we are file-dependant, and we would need to update the file frequently (cause the schema changes easily and somehow we don't really control those changes: AndroMDA generates the tables and Hib mapping from the schema). Besides, i have a problem with Hibernate dialect: this one is defined to <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop> in applicationContext.xml, but i didnt manage to change it programatically for the tests to <prop key="hibernate.dialect">org.hibernate.dialect.HSQL Dialect</prop>. So i put a custom applicationText-test.xml for my tests, but i have been told it's not really clean...
    - HSQL in-memory + JUnit: we need to populate the database... how? i gues we can through a big huge SQL query, but then we have the same problem than before...
    - Unitils, an open-source unit testing framework, which combines JUnit, DBUnit, Spring context files.... it seems powerful but i'm afraid it's a bit young... and if we lose time using it? And anyway it would require some time to understand all the features... and what about Maven 2 integration?
    - DBUnit? But am quiet unsure how to use it...
    Last edited by nicdo77; Aug 5th, 2007, 10:13 AM.