Showing posts with label Test. Show all posts
Showing posts with label Test. Show all posts

Wednesday, October 17, 2012

How to unit test a classic Web Site project (app_code)

I recently worked on a legacy system (banking) containing several old Web Site projects (needless to say they were "thick" and not backed up by any tests). As a strong believer in the value of unit tests I wanted to write isolated tests to express the business intention behind the logic as well as proving it actually worked (without the need to find test data in an environment that includes many 3rd party systems and platforms).

So what are your options when it comes to unit testing code in a classic Web Site (app_code) based project? Or first off, what is the challenge? Well, classic Web Site projects rely on run-time compilation so there's no way to just add a reference to the assembly/project under test as you normally would do. Or is it?

If you do some search on the topic you'll find various suggestions:
  • "Migrate the Web Site project to a Web Application project"
    Sure - I'd definitely opt for this solution if you can get away with it. In my case such a change would require changes to a quite complex build/deploy process as well so it was not a feasible short term solution.
  • "Move the code to be tested from the app_code folder into a separate class library"
    My new code had a lots of dependencies to existing code that lived under the app_code folder, so it  would have been a quite large change...again not feasible at this point in time. 
  • "It's not possible"
    Writing code that can't be unit tested is a personal no go, so that kept me searching for another solution...

....and here's what I ended up with: 

  1. Create your unit test project
  2. Create a precompile->output folder structure in the unit test project.

  3. Edit the unit test .csproj file and add a pre-compile step to trigger a build of the Web Site project that contains the code you'd like to unit test.
    PhysicalPath: The Web Site project you'd like to write tests against
    TargetPath: The relative path to the folder you created in step 2.

  4. If you now build your unit tests project you should see the precompile->output folder getting filled with binaries from the Web Site project.
  5. Voila - you can now go ahead and add a reference to the precompile->output->bin->App_Code.dll. Every time you re-build our solution the referenced App_Code.dll assembly will be updated as expected.

Thursday, April 22, 2010

Installing TestLink on a Windows Server 2008

In this article I will provide a guide on how to install TestLink on a Windows Server 2008 box.

First off, TestLink is an open source web based test management system build in PHP available for download at
http://sourceforge.net/projects/testlink/

I've used it in one of my projects and I find it quite useful.
Especially together with a tool/framework for GUI driven test automation such as WebAii or WaitN. Then tests can be documented in TestLink and implemented in the test automation tool for quick and easy execution.

Any how, the basic requirements for setting up TestLink on Windows Server 2008 are:
  • IIS
  • PHP
  • A DBMS (in this guide I will use MySQL)
Step 1 - Install IIS
I will not provide any detailed instructions here, simply make sure the server has been assigned the Web Server role.

Step 2 - Install PHP 5.x on top of the IIS
  1. Download PHP 5.x for Windows from http://windows.php.net/download/
    (a x64 version does not currently exist, but the x86 version works fine)
    I used the .msi install even though many other PHP intallation guides recommends the .zip and manual install.
  2. Add a new handler mapping to IIS


(NOTE: If you used the .msi install the default installation folder for PHP will be c:\Program Files (x86)\PHP)




Step 3 - Install MySQL
TestLink supports both MySQL and Microsoft SQL Server. If you have a SQL Server that you intend to use for storing TestLink data then skip this step.
  1. Download MySQL
    http://dev.mysql.com/downloads/mysql/
  2. Run the downloaded .msi and create a root DB account.
  3. Download and install MySQL Workbench
    http://dev.mysql.com/downloads/workbench/5.1.htm

Step 4 - Download and install TestLink
  1. Download the TestLink .zip from the following location
    http://sourceforge.net/projects/testlink/
  2. Unzip the file to a local folder, e.g. C:\Testlink
  3. Create a new Web Site in the IIS Manager and select the unzip folder in step 2 as root.
  4. In a web browser, load http://localhost/index.php
  5. Click the link “New installation”

  6. Make sure the read/write permissions are ok. If not, change the Identity (user account) used by the application pool associated with the TestLink web site from the default ApplicationPoolIdentity to NetworkService, and right-click on the C:\Testlink folder and add full permissions to the "NETWORK SERVICE" account.

  7. Under the “Database Configuration” section on the same page, enter the DB settings.

  8. Click the “Process TestLink Setup!” button.
  9. On the next page, check the “I agree to the terms set out in this license” radio button and click the “Proceed” button.
  10. Make sure the installation was successful
Voila - you're done!

Monday, October 12, 2009

WebAii testing - Invoking javascript eventhandlers

It's certainly easy to handle JavaScript events and AJAX in WebAii.

Here is what my GUI looks like:
A cascading dropdown scenario, where the dropdowns are wrapped in an ASP.NET AJAX UpdatePanel. When a user selects an item in the industry/profession dropdown the position dropdown will be re-populated with items valid for the selected industry/profession.


WebAii code:
To be completed...