3

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.

4

4 回答 4

3

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.

于 2009-05-05T22:56:40.753 回答
1

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.

于 2009-04-30T08:35:32.237 回答
0

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.

于 2009-04-30T14:40:19.083 回答
-2

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).

于 2009-04-30T00:58:28.700 回答