java - TestNG - WebDriver - Web apps Testing - Independent Tests -


how handle db inside of script using testng framework? how delete db before each run of test script? how load sql file clean db before running test script?

goal: each test case must independent framework: testng language: java

each test case must independent against other test cases. goal run test cases randomly, no order required.

previously have used phpunit framework each test case independent.

before running each test script, would:

  1. dropdatabase
  2. create new database
  3. load sql file database initial data

i using inside of shell script, , call shell script via command line:

mysql -u$db_user -p$db_pwd -h$host -e "drop database $db_name"

mysql -u$db_user -p$db_pwd -h$host -e "create database $db_name"

mysql -u$db_user -p$db_pwd -h$host $db_name < sql/dbinit.sql

google-ing not helpfull, therefore posting question here. need testng have not found similiar.

could give advice fellow qa. how handle oracle database, how delete data db , load them inside of test script?

any advice, book, tutorial helpfull.

you should dbunit. i've started using myself (i'm testng user) and, of yet, haven't come across scenarios absolutely need junit itself. can restore database between tests, populate it, export it, etc ...

http://dbunit.sourceforge.net/

basic example:

private databasehelper dbh; private entitymanager em; private idatabaseconnection connection; private idataset dataset;  @beforeclass private void setupdatabaseresource() throws exception {     // using jpa , custom helper class     em = dbh.getentitymanager();     connection = new databaseconnection(((sessionimpl) (em.getdelegate())).connection());      connection.getconfig().setproperty(databaseconfig.property_datatype_factory, new hsqldbdatatypefactory());      // full database export     idataset fulldataset = connection.createdataset();      flatxmldataset.write(fulldataset, new fileoutputstream("target/generated-sources/test-dataset.xml"));      flatxmldatasetbuilder flatxmldatasetbuilder = new flatxmldatasetbuilder();     flatxmldatasetbuilder.setcolumnsensing(true);      // keep dataset in memory, later restore points     dataset = flatxmldatasetbuilder.build(new fileinputstream("target/generated-sources/test-dataset.xml")); } 

edit: example @beforemethod restores database between tests

@beforemethod public void cleandb() throws exception {     databaseoperation.clean_insert.execute(connection, dataset); } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -