Rank: Member
Joined: 11/5/2003(UTC) Posts: 2,136
Was thanked: 1 time(s) in 1 post(s)
|
I have written quite a few unit tests for my code (~300 for the Shipping Rate Provider Suite), but some BVC5-related testing is quite difficult. For example processing an order in a workflow may force BVC5 to retrieve the current user from the HttpContext in order to calculate the price. But my unit tests are not running within an HttpApplication so there is no HttpContext. Crash...burn... What I do is create a temporary HttpContext that has just the features I need to finish the test. Today I ran across a robust HttpContext simulator called HttpSimulator. I plan on giving this a try for new unit tests. In the mean time I thought some of you other developers might like the link. |
|
|
|
|
Rank: Member
Joined: 11/5/2003(UTC) Posts: 1,786
|
Sounds cool. Let us know how it goes.
|
|
|
|
Rank: Member
Joined: 8/17/2006(UTC) Posts: 681
|
Andy, Have you tried using WATIN? (http://watin.sourceforge.net/). I found it extremly succesfull in the last project I worked. It's free and very easy to use from .Net to write UI Unit Tests.
Corneliu. |
|
|
|
|
Rank: Member
Joined: 11/5/2003(UTC) Posts: 2,136
Was thanked: 1 time(s) in 1 post(s)
|
Originally Posted by: "Corneliu Tusnea" Andy, Have you tried using WATIN? (http://watin.sourceforge.net/). I found it extremly succesfull in the last project I worked. It's free and very easy to use from .Net to write UI Unit Tests.
Corneliu.
Yes I have and Selenium. Both are great for testing UI stuff. HttpSimulator is for testing code that needs a context, but is not UI. For example when calculating the price of a product, BVC5 will check the logged in user to see if a discount or pricing level applies. So if I want to test some of my code that indirectly causes BVC5 to calculate the price on something, then I need to create an HttpContext before I run the test. No UI involved, just some context stuff. |
|
|
|
|
Rank: Member
Joined: 11/5/2003(UTC) Posts: 2,136
Was thanked: 1 time(s) in 1 post(s)
|
So far so good. I replaced some convoluted code in my TestFixtureSetUp that looked like this: Code: if (HttpContext.Current == null) { Thread.GetDomain().SetData(".appDomain", "test"); Thread.GetDomain().SetData(".appPath", Assembly.GetExecutingAssembly().[b][/b][b][/b]location); Thread.GetDomain().SetData(".appVPath", "/"); HttpRequest request = new HttpRequest("", "[url=http://localhost/]http://localhost[/url]", ""); request.Browser = new HttpBrowserCapabilities(); request.Browser.Capabilities = new Dictionary<string, string>(); request.Browser.Capabilities["[b][/b][b][/b]cookies"] = "false"; HttpContext.Current = new HttpContext(request, new HttpResponse(Console.Out)); }
with something much simpler: Code: if (HttpContext.Current == null) { new HttpSimulator("/", Path.GetDirectoryName(Assembly.GetExecutingAssembly().[b][/b]location)).SimulateRequest(); }
My code works for the web features I currently use, but it is very fragile. For example a week ago I added a test that called something in the BVC5 which used something in System.Web that failed because the browser capabilities did not include " cookies". I spent quite a bit of time figuring out what caused the error and then using Reflector on System.Web to figure out what was missing. Yuck. I have more confidence that HttpSimulator will be much less fragile. I am also going to look at TypeMock. |
|
|
|
|
Rank: Member
Joined: 4/4/2004(UTC) Posts: 670
|
Thanks Andy. Appreciate that you took the time to post the links.
Scott Mech
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.