James's profileJames McCaffreyBlogLists Tools Help

Blog


    July 30

    Cross Frame Access with jQuery

    I am researching the use of jQuery for Web application test automation. One of the things I need to do is access HTML elements in one frame from another frame. A search of the Internet yielded several people asking how to do this but no answers. Anyway, after about two hours of work I came up with a solution to the problem. The screenshot below shows a demo in action. The main page has two frames. When a user clicks on the Set Text button in the page in left frame, control is transferred to a jQuery function which places text into the text box control in the right frame. The key lines of code are:
     
    $(document).ready(function(){
     $("#Button1").click(function(){
      $(parent.rightFrame.document).contents().find('#TextBox1').val('Hello from left frame!');
     });
    });
     
    Anyway, jQuery is very cool and I should have a Web application test automation article written for MSDN Magazine done in a few weeks.
     
     
    July 24

    Eigenvalues, Eigenvectors, and Software Testing

    You have probably heard the terms eigenvalue and eigenvector before but probably aren't sure exactly what these terms mean. They are staples of discrete mathematics courses required for computer science degrees at many universities. For years I've wondered if eigenvalues and eigenvectors have any application to software testing. I don't have an answer. Let me explain what eigenvalues and eigenvectors are, and why I suspect they might be important to software testing. Suppose you are dealing with points x = (x,y) in the two-dimensional plane. Then a 2x2 square matrix A implicitly defines a transformation of any point. Bear with me here. If there exists a vector x and a value λ (Greek letter lambda) that have the relationship Ax = λx then λ  is called an eigenvalue and x is called an eigenvector. For example, if A = [ (6,3), (-2,-1) ], and λ = 0, and x = [1,-2] the λ and x form an eigenvalue-eigenvector pair. OK, so what? One of the surprising things about eigenvalue analysis is the amazing number of real-world problems they apply to in very unexpected ways. For example, using eigenvalue analysis it was shown that the optimal shape of a building support column is curvy, somewhat like the shape of a decorative stair post. Anyway, software testing is all about state changes which can be represented mathematically as vectors and matrices. There may be some interesting and useful ways that eigenvalues and eigenvectors can be applied to software testing.
    July 18

    Web Application UI Testing with jQuery

    The open source jQuery library is a collection of JavaScript functions that allow Web developers to create client-side effects such as fade-in and fade-out more quickly than by using plain JavaScript code. I have been looking at using jQuery to write simple, lightweight Web application UI test automation. The main advantage of using jQuery for test automation rather than using raw JavaScript is that the functions in jQuery work with multiple browsers (IE, Safari, Firefox, etc.) The screenshot below shows an example of testing a simple Web application using jQuery. The frame on the left hosts a jQuery test harness script, and the frame on the right hosts the Web application under test. I intend to write an article for MSDN Magazine which describes all the details. 
     
     
    July 10

    Comparing Actual Results to Expected Results with the Log Likelihood Ratio

    One of the core principles of software testing is that in order to determine a pass/fail result for a test case, after executing the test case you must compare the actual result or state of the system under test with an expected result/state. For example, if you are testing the + functionality of a calculator, and the test case inputs are 3.0 and 4.0 (and the expected result is 7.0) then you exercise the SUT to get an actual result and compare that actual result with the expected result. In statistics, the most common way to compare a set of observed values with a set of expected values is to use the well-known chi-square test. However, what is not so well known is that the chi-square test is actually a discrete approximation to the log likelihood test. The chi-square test was developed in the days before calculators when computing logarithms was difficult. Anyway, the point is, in software testing, if you want to compare how close a set of actual values is to a set of expected values, you should probably use the log likelihood g-test rather than the chi-square test. The g statistic is given by 2 * (sum-over-i(Oi * ln(Oi / Ei)) where Oi is an observed value and Ei is the corresponding expected value. For example, suppose you have some system which should emit the three values (4.0, 4.0, 4.0). These are the expected values. Now if the actual results are (3.0, 4.0, 6.0) then the g-statistic is 2 * [(3.0 * ln(3.0/4.0)) + (4.0 * ln(4.0/4.0)) + (6.0 * ln(6.0/4.0))] = 3.139. The closer the g-static is to 0, the closer the actual results are to the expected results; you can look up specific probabilities if necessary.
    July 06

    Number of Ways to Partition a Set of Items

    Partitioning a set of items is a problem I run across rather often. Determining the number of ways you can partition a set of n items into k groups is a surprisingly difficult problem. Suppose you have a set of n = 4 items and want to partition those items into k = 2 groups. How many ways can you do this? There are 7 possible partitions of 4 items into 2 groups:
     
    (a)   (b,c,d)
    (b)   (a,c,d)
    (c)   (a,b,d)
    (d)   (a,b,c)
    (a,b)   (c,d)
    (a,c)   (b,d)
    (a,d)   (b,c)
     
    It turns out that the number of possible partitions is given by an equation called Stirling numbers of the second kind, S(n,k). It is an interesting function which increases very rapidly. S(4,2) = 7 and S(6,4) = 65. I was working on a problem recently with n = 435 (the number of members in the U.S. House of Representatives) and k = 2. The number of ways you can partition 435 items into 2 groups is 4.4 * 10 to the 130th power. This is an unimaginably huge number. Wikipedia has a good article on Stirling numbers of the second kind if you want to know more.