views:

388

answers:

4

I'm wondering how people are currently resetting their data / cleaning up test remnants for their WatiN/Wartir tests?

For example, lets say there's a test to add a user into the system and the username has to be unique. Obviously the first run without any users should work fine, but the second run will fail without manual intervention.

A: 

WatiN is for UI testing.

In order to test the scenario you are looking for, you can generate user id using the c# code that will make it unique (as against the way it is stored when you created the test).

shahkalpesh
I understand that WatiN is for UI automation testing, but it's also useful for functional testing in which we are attempting to using it for.Unfortunately this is already what we are doing. The problem is it's not really elegant and can fail from time to time randomly and the test database bloats after awhile.What I'm really looking for is a transactional solution where the data can be rolled back after the test.
Mike737
+1  A: 

I have asked a developer to make a script that will reset database. After a suite of tests, I just call that script and start from clean database.

Željko Filipin
A: 

Mike - your question isn't unique for Watir/WatiN. It applies for any UI testing, so search around for similar solutions for Selenium, Windmill, and even headless integration tests (HtmlUnit, API tests, etc). I've answered this question a couple times personally on StackOverflow.

Patrick Lightbody
+2  A: 

There are a couple of strategies that you could do for this, I am assuming that you are using WatiN, with Nunit or VS Unit tests to run your tests.

Use transactions An approach that is used when unit testing is that you "wrap" the whole test in a transaction and at the completion of the test roll the transaction back. In .net you can use System.Transactions for this.

Build a "stub page" Build a page in your applicaiton that uses the existing business logic to delete your data. This page would need to be secured and ideally not even deployed in to production. This is the approach that I would recommend.

Call a web service Develop a web service, or call one directly from the app tier of the applicaiton to perform the delete. You will probably need to develop this as well.

Clean up directly Build some classes in your test code to access the data and clean it up.

With any of these you will need to cleanup before and after you run your test, i.e. in the test setup and test cleanup methods. The reason to do it twice is that you should assume that your test has failed and not cleaned up properley.

Use Linq to Sql AFAIK if you are using Linq to sql, it works in-memory and wraps the whole update in a transaction for you automatically. If you simply don't call the SubmitChanges(); method then you should be fine, but I haven't tested this myself.

Bruce McLeod
How would you work with System.Transations when you are doing transaction commits in LinqToSql?
Mike737