Tuesday, May 22, 2007

Light-Weight ASP.NET Unit Testing - Go Browser-less, Server-less!

ASP.NET comes with great set of features especially for extensibility. Web Hosting is one of those features that is extremely poweful but not widely used since it's not really common for web developers to need to host their own ASP.NET processing server.

When it comes to testing, there is great power and agility gained with having a host processing requests within the test process. It allows us to eliminate the need for a browser and a webserver. It allows for an extemely quick and light-weight execution of tests that is suited for scenarios such as:

  • Running Build Verification Tests (aka BVTs): These tests commonly run as part of a continuous integration server process and they are very basic tests that ensure basic functionality and cover a broad set of features but do not go deep into each feature. BVTs can also be used during the dev check-ins process to ensure certain code quality at check-in. Having a quick turn around on these tests is important so they don't become a bottle neck for product building and development check-in.
  • UnitTesting business logic behind UI elements: If you want to write unit tests for your business logic that is tightly coupled with certain UI elements or UI logic.
  • Any other testing that does not require client javascript execution or a browser.

The Plasma project on codeplex attempts to accomplish that but is still at a very early stage in development. With WebAii Beta2 refresh, we updated WebAii to include a similar Asp.Net host and integrated it with our DOM parser, element identification engine and Actions interface. We enabled the scenario of executing ASP.NET Unit Tests using a light weight process without a need for a browser or a webserver.

The Actions object implements all the common actions like Click(), SetText(), SelectDropDown()..etc. which is the same interface you would use to automate IE or Firefox; so there is no new interface to learn or setups to perform. Simply flip a switch in your settings and you are automating without a browser or a server.

So what do you need to do to enable automation with WebAii using an in-process host? Simply set the defaultBrowser config setting to AspNetHost or set it in your code if you are not using a config:




<WebAii.Settings


defaultBrowser="AspNetHost"


logLocation="c:\Log\"


webAppPhysicalPath="C:\Aot\webtest\artoftest.testing\pages"


enableScriptLogging="false"


>



Or set it in your test code:

settings.DefaultBrowser = BrowserType.AspNetHost;

And Voila! That is about it. You can automate your tests using the same Find.Byxx or Actions..xx and with no browser/server needed.

What about debugging?

With browser-less automation, you get the quick, snappy execution but you lose the visual rendering of your pages. But that is no longer the case with WebAii. If you want to visually view the responses coming back from the in-process server, simply set the setting:
enableUILessRequestViewing to true and you will get an IE instance that simply renders the response visually. You can set break-points in your code if the execution is going too fast to notice specific pages.

If you want to learn more about this feature, check out our documentation on the in-process host here. You can also download our complete samples here which include a sample using AspNetHost.

1 comment:

Unknown said...

There remains no bound when you have such a great variety of replica handbags provided by the company. You can easily choose from their greatest designer replica handbags collection and because of the replicas being available to you, the price is also not something that would stop you from not purchasing these items. The designer handbags has everything what should be a part of the material for making the perfect looking designer bags .