• Toll-free  888-665-8637
  • International  +1 717-220-0012
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Andy Miller
#1 Posted : Thursday, June 21, 2007 2:47:17 PM(UTC)
Andy Miller

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.
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing
Marcus
#2 Posted : Saturday, June 23, 2007 8:44:59 PM(UTC)
Marcus

Rank: Member

Joined: 11/5/2003(UTC)
Posts: 1,786

Sounds cool. Let us know how it goes.
CorneliuTusnea
#3 Posted : Sunday, June 24, 2007 8:55:05 AM(UTC)
CorneliuTusnea

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.
http://www.bestgames.com.au
http://www.bestchess.com.au



BV Product Links, Details and Signatures: Improve your customer experience:

http://www.acorns.com.au/projects/bv/quicklink/

Andy Miller
#4 Posted : Sunday, June 24, 2007 10:31:19 PM(UTC)
Andy Miller

Rank: Member

Joined: 11/5/2003(UTC)
Posts: 2,136

Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: "Corneliu Tusnea" Go to Quoted Post

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.
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing
Andy Miller
#5 Posted : Wednesday, June 27, 2007 11:38:15 AM(UTC)
Andy Miller

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.
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing
scott.mech
#6 Posted : Sunday, August 19, 2007 3:14:17 PM(UTC)
scott.mech

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.

©2025 Develisys. All rights reserved.
  • Toll-free  888-665-8637
  • International  +1 717-220-0012