java - how to quickly create a test database for Cucumber-jvm? -


i using cucumber-jvm test behaviour of legacy system i'm working on @ work. have use java 1.5 , hibernate 3.3, upgrading not option. since, during tests, stores objects in database, have created new development database.

what bothers me have manually drop records (using sql script) everytime i'll rerun tests, or they'll fail. , else wanting run them have same. want , automatically clean test database, either:

  • creating empty database , populating need, or
  • using existing database, droping records before starting tests.

what have far: i'm using cucumber-junit plugin, , runtests class redirects test database:

@runwith(cucumber.class) @cucumber.options(     features = "test/resources/cucumber",     format = "html:target/cucumber" ) public class runtests {     private static configuration configuration;      @beforeclass     public static void preparabase() {         // gets mapped configuration db         configuration = hibernateutil.getconfiguration();          configuration.setproperty("hibernate.connection.url", "test-db-url");         configuration.setproperty("hibernate.connection.username", "user");         configuration.setproperty("hibernate.connection.password", "pass"); //      configuration.setproperty("hibernate.hbm2ddl.auto", "create-drop");          // rebuilds configuration using test database         hibernateutil.rebuildsessionfactory(configuration);     } } 

i have tried using hibernate.hbm2ddl.auto property create-drop value , using import.sql file prepare database, takes ages start tests , seems it's not detecting import.sql file.

sadly, using maven , excellent maven-sql-plugin not option (i have suggested switch maven, no avail). there alternative?

i did it!

i used scriptrunner class such:

@runwith(cucumber.class) @cucumber.options(     features = "test/resources/cucumber",     format = "html:target/cucumber" ) public class runtests {     private static configuration configuration;     string url = "test-db-url";     string user = "user";     string pass = "pass";      @beforeclass     public static void preparabase() {         // gets mapped configuration db         configuration = hibernateutil.getconfiguration();          configuration.setproperty("hibernate.connection.url", url);         configuration.setproperty("hibernate.connection.username", user);         configuration.setproperty("hibernate.connection.password", pass);          // rebuilds configuration using test database         hibernateutil.rebuildsessionfactory(configuration);          // executes script stored in test/resources/cucumber         try {             class.forname("com.mysql.jdbc.driver");             connection conn = drivermanager.getconnection(url, user, pass);             scriptrunner runner = new scriptrunner(conn, false, true);              runner.runscript(new bufferedreader(new filereader("test/resources/cucumber/db.sql")));         } catch (exception e) {             throw new runtimeexception(e.getmessage(), e);         }     } } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -