Friday, April 27, 2012

Using sandboxing in your tests

As you know mocks aren't stubs: stubs are used to return canned data to your system under test, so that you can make some assertions on how your code reacts to that data. Mocks, on the other hand, are used to specify certain expectations about how the methods of the mocked object are called by your system under test. But you should still use a mock library or framework even when you want to use stubs, because these libraries make it very easy to instantiate and work with stubs.

Recenlty I've discovered another interesting approach. It's provided by the tl.testing package that allows to sandboxe of directories and files. Here is my example. This code implements a search for a given string in files. I use doctest to check the functionality.


Tuesday, November 29, 2011

InfoQ: Brian Marick on Test Maintenance

Very interesting: Brian Marick discusses the difficulties met trying to maintain tests that are vital to a project’s success, and how mocking frameworks can help, providing advice on writing unit and integration tests InfoQ: Brian Marick on Test Maintenance
"The Expression Problem is a new name for an old problem. The goal is to define a datatype by cases, where one can add new cases to the datatype and new functions over the datatype, without recompiling existing code, and while retaining static type safety (e.g., no casts)."

Wednesday, November 23, 2011

Each new user of a new system uncovers a new class of bugs.

Monday, October 3, 2011

CSS property Overflow & scroll bar: how to test

The CSS property Overflow can be used when displaying content. It regulates the scrollbars. You can use 4 variables in the element overflow, namely auto, hidden, scroll and visible. Auto will automatically add a scrollbar when needed. Hidden will not show a scrollbar, but ‘hide’ the content that usually expand the box. Scroll will always add a scrollbar. The value visible will not expand the div, but will just display all the content without changing the div’s height.

Very convenient technic if you want to let a scroll bar appear when content of your DIV gets to a specific height. For more details you can read this article for example, but in this tutorial I'm going to cover testing aspects of this technic.

Actually here there is a problem. How is it possible to check that your scroll bar appears or not when dynamic content of your DIV changes? You can't just get a visibility of the scroll bar and verify it. But we can use the scrollTop jQuery method, that gets the current vertical position of the scroll bar for the given element: the vertical scroll position is the same as the number of pixels that are hidden from view above the scrollable area. If the scroll bar is at the very top, or if the element is not scrollable, this number will be 0.

The first scrollTop call with the position parameter sets the current vertical position of the scroll bar for the given element. If this element is scrollable, the second empty scrollTop call will return value that is equal the given position value, otherwise it will return zero.

Monday, March 21, 2011

Using FITNesse and Selenium for acceptance testing, example 2

This example is about using FITNesse QueryTable fixture with Selenium. Let's consider next scenario. There is a list of SharePoint sites and an administrator can grant permissions to users for any site in this list. A result of such action is a report that contains list of the users with sites they have permissions for.

The best way to check that the action is competed succefully is to check that given user is presented in this report and has appropriate permissions set. It is very easy to do using the QueryTable fixture.

Just define a class with the query method and a constructor that takes a user name. Pay attention that this QueryTable class should aggregate the Browser class instance to access data on the html page.

But actually here is a problem. An architecture of FITNesse does not allow the PermissionsActionsReport QueryTable class instance to access existed instance of the Browser class that was used to make the action and that contains the result of this action. Fortunately this obstacle can be solved easy using the singleton pattern.

Sunday, March 13, 2011

Using FITNesse and Selenium for acceptance testing, example 1

I have alredy written that Fitnesse+SLIM+Selenium is a pretty powerfull tandem to be used for testing web applications. Also I have a blog post about Selenium 2/WebDriver that is much better for testing web applications than first Selenium. In this and upcoming posts I gonna to share my experience of testing complex use cases in my web application using Fitnesse and WebDriver.

For example, there is a list of the SharePoint Sites. You can use checkboxes and a toolbar to select and execute a set of actions for them. Let's do Copy List: select a site and click the Copy List button. It will araise the Select Lists dialog box.
Here you have to select lists what you want to copy and press the Next button. In the next dialog box it's necessary to select target site. Actually a list of these site can be very long. But there is a search here that allows you to narrow a scope: type a name of site that you want to target and press the Search button. Now find the site in the search result and press copy.
Now wait for operation to be completed.
Actually the scenario forks here. It can be completed successfully or not.
If operation is failed, you will see an error description and can click to the SharePoint log files link to see more details.
Here the fitnesse test that checks this scenario.
And here it's code

As you can see the working element here is the Browser python class