Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rollback Database after running Selenium GUI tests

I am using Selenium GUI tests in a Java Web Application. Since these tests are actually client, how can we rollback database after running a test?

like image 485
Java Developer Avatar asked Oct 28 '25 16:10

Java Developer


2 Answers

What you're after is called Fixture Teardown Patterns. Since you need to keep track of all resources that are created in a test and automatically destroy/free them during Teardown. I obviously don't know your framework, but for this case

rollback database after running a test

a good candidate is the Inline Teardown. It includes teardown logic at the end of the Test Method immediately after the result verification. Like so:

enter image description here

like image 78
ekostadinov Avatar answered Oct 30 '25 06:10

ekostadinov


My guess is that you can't 'roll back' the database since web applications typically commit transactions between requests.

You'll need to implement your own custom rollback. Perhaps you could create a new user for each test and remove any changes made by this user after the test. Or maybe you want to implement the command pattern.

You might also find a cascading delete helpful

like image 23
lance-java Avatar answered Oct 30 '25 06:10

lance-java