I am in a situation where I have to revert all the changes which I made while testing the application. Is there any way of doing this in Testng?

Suppose if I have added something into the application during testing add functionality. now when I am tearing down this test case, I have to revert the changes. Any suggestions how to do this?

If I have deleting functionality then I can delete that added thing in tear down. but that would be a kind of test case for delete functionality into a tear down process. isn't it?

Also if we don't have any delete functionality then. Anyone who knows how to revert the changes, please suggest.

I am taking selenium webdriver and testng in use.

5 Answers 5


Like Josa Pita says, that is nothing for testing frameworks itself.

The developers could write a script to save the current version of the DB. The process should look like that:

  1. Save current version of DB/any kind of data storage.
  2. Start test run.
  3. After test run finished restore the saved version of the DB/any kind of data storage.

But I think it is only a solution for Applications with not too big databases/any kind of data storage. You also could have troubles with manual tests while the test run.

But the best solution would be a own test environment with a own database/any kind of data storage. Also talk to the developers. Tell him your trouble and find a solution together.


Suggestion: Every test automation shall run in a dedicated environment, dev code/script/db changes shall always auto deploy to this environment, automated test shall only run here. With such design the team can easily design the automated test an test data as well. After each success test execution, restore the whole db.


From what I understand from your question, you want to delete the records of the actions you made on your app?

This has nothing to do with selenium or testng, you need to have an app for tests only, with a clean DB, that you can delete the records from your actions.

Is this helpful?

  • I don't have DB's. I just run my tests on projects deployed on server. Commented Jul 2, 2014 at 9:58
  • So you can't revert any changes you made? Commented Jul 2, 2014 at 13:25
  • thats what.. I don't have access to DB.. at most I can write revert test functions which will perform operation to change what I did in testing process. but here also a problem is there that suppose application has just adding facility then once i add i can't revert. Commented Jul 22, 2014 at 12:33

You can do the below two things

  1. Create a database snapshot before the test begins and restore to that snapshot after the test run
  2. Create an actual backup through your application and restore to the backup post run.

While approach 1 is less of hassle please be advised that the snapshots are not actual copy of the full database and can not be considered as reliable backups to fall to. The second approach is more expensive in terms of time but is more robust and reliable.


I would have each test create its own test data before execution. So if the application has different users, then create a unique user and any data needed for that test. That way data for one test does not interfere with any other tests.

If you use snapshots it can get confusing to keep track of which data was for which test as the number of tests increases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.