| Profilo di JamesJames McCaffreyBlogElenchi | Guida |
|
29 maggio Character Encoding and TestingStarting last week, I have been teaching a class to prepare software test engineers for a Certificate in Software Testing with Microsoft Technologies program. The certificate program covers 42 specific topics that were listed by test managers as those topics that testers should have at least a basic understanding of. One of those 42 topics is character encoding. Yesterday morning I decided to make a tiny demo program to use to illustrate the topic. I recalled that one of my colleagues, William Rollison, is an expert at character encoding. I visited his blog and found a tool he wrote, and I decided to (approximately) reverse engineer that tool so that I could have a simple application with source code to distribute to students in the software testing certificate program. The screenshot below shows the result.
Interestingly, the character encoding logic was simple (in part because I've investigated the topic before) but I spent an hour wrestling with the ListView data control to display results. The demo is written with C#. Here's the code:
private void button1_Click(object sender, EventArgs e)
{ listView1.Items.Clear(); int charCount = 0; string s = textBox1.Text; char[] chars = s.ToCharArray(); foreach (char c in chars) { char[] arrayWithOneChar = new char[] { c }; byte[] bytes = null;
if (radioButton1.Checked) // ASCII bytes = Encoding.ASCII.GetBytes(arrayWithOneChar); else if (radioButton2.Checked) bytes = Encoding.Unicode.GetBytes(arrayWithOneChar); // Little Endian else if (radioButton3.Checked) bytes = Encoding.BigEndianUnicode.GetBytes(arrayWithOneChar); else if (radioButton4.Checked) bytes = Encoding.UTF7.GetBytes(arrayWithOneChar); else if (radioButton5.Checked) bytes = Encoding.UTF8.GetBytes(arrayWithOneChar); else if (radioButton6.Checked) bytes = Encoding.UTF32.GetBytes(arrayWithOneChar); string bytesForACharInHex = ""; string bytesForACharInDecimal = ""; foreach (byte b in bytes) { bytesForACharInHex += b.ToString("X2") + " "; bytesForACharInDecimal += b.ToString() + " "; } listView1.Items.Add(new ListViewItem(new string[] { charCount.ToString(), c.ToString(), bytesForACharInHex, bytesForACharInDecimal })); ++charCount; } // next char } // button1_Click() 25 maggio Generating All PermutationsTwo of the most common and fundamental programming tasks are generating all possible permutations, and generating all possible combinations. Last week I spent some time looking at what I'd find on the Internet about these two problems. I was surprised by the large number of Web pages and blogs which have really, really bad information. First, the terms permutations and combinations, are used incorrectly on many Web sites. A mathematical permutation of order (size) n is a rearrangement of the numbers 0 through n-1. For example, if n=3, then all possible permutations are {0,1,2}, {0,2,1}, {1,0,2}, {1,2,0}, {2,0,1}, {2,1,0}. Here I've listed the permutations in lexicographical order. A mathematical combination of order (n,k) is a subset of size k of the numbers 0 through n-1 where order does not matter. For example, all combinations of order (5,3) in lexicographical order are {0,1,2}, {0,1,3}, {0,1,4}, {0,2,3}, {0,2,4}, {0,3,4}, {1,2,3}, {1,2,4}, {1,3,4}, {2,3,4}. Anyway, listed below is a tiny class, written in C#, with error-checking removed, that will generate all possible permutations. The class can be called like this:
static void Main(string[] args)
{ Console.Write("\nEnter permutation order (n): "); int n = int.Parse(Console.ReadLine()); Console.WriteLine("\nAll permutations: \n");
Permutation p = new Permutation(n); while (p != null) { Console.WriteLine(p.ToString()); p = p.Successor(); } Console.WriteLine("\nDone");
} Notice the approach is to define a Successor() method which returns the next permutation object, or null if we are at the last permutation. Here's the class:
public class Permutation
{ public readonly int n; public readonly int[] data; public Permutation(int n) {
this.n = n; this.data = new int[n]; for (int i = 0; i < n; ++i) data[i] = i; } public override string ToString()
{ string s = "( "; for (int i = 0; i < n; ++i) s += data[i] + " "; s += ")"; return s; } public Permutation Successor()
{ Permutation result = new Permutation(n); int left, right; for (int i = 0; i < n; ++i)
result.data[i] = this.data[i]; left = result.n- 2; // Step #1 - Find left value while ((result.data[left] > result.data[left + 1]) && (left >= 1)) --left; if ((left == 0) && (this.data[left] > this.data[left + 1])) return null; right = result.n - 1; // Step #2 - find right value
while (result.data[left] > result.data[right]) --right; int temp = result.data[left]; // Step #3 - left and right result.data[left] = result.data[right]; result.data[right] = temp; int x = left + 1; // Step #4 - order the tail int y = result.n - 1; while (x < y) {
temp = result.data[x]; result.data[x++] = result.data[y]; result.data[y--] = temp; } return result;
} } // Permutation 16 maggio Retrieving Text from a .NET ListBox Control using the MUIA LibraryI ran into an interesting technical riddle yesterday. I was writing some demonstration UI test automation for a class which is part of a new Certificate in Software Testing with Microsoft Technologies program. My application under test is a .NET Windows application that plays a hypothetical game of two-card poker. I was using the Microsoft UI Automation library to implement my UI test automation. Everything went according to plan until I decided I'd like to examine the contents of a ListBox control as part of the process of determining the final state of the app under test (in order to determine a pass/fail result). It turns out that there are no existing published examples of how to do this. I spent a couple of hours but finally came up with the correct approach. See the screenshot below.
In words, first get a reference to the ListBox control itself. Next get a reference to that control's ListItem collection. Next use zero-based array indexing to get a reference to a particular item in the collection. And then use the Name property of that item to get the text. The trick is the last step. I had been trying to use the MUIA TextPattern and ValuePattern patterns. It turns out that the Name property of a ListItem item reflects the text contents. So, the code to fetch the contents of a .NET ListBox control using the MUIA library resembles the following:
AutomationElement aeListBox = aeForm.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List)); AutomationElementCollection aeListBoxItems =
aeListBox.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem)); AutomationElement aeFirstItem =
aeListBoxItems[0]; string s =
(string)aeFirstItem.GetCurrentPropertyValue( AutomationElement.NameProperty); Anyway, like always, the answer seems obvious once you know it. I believe that the MUIA library will become the de facto standard technology for UI test automation of Microsoft programs, once all the little recipes like the one I've presented here become well known.
08 maggio Software Testing CertificationI've been working informally with several groups at Microsoft to create a certificate in software testing program. The idea is to provide all testers with a basic knowledge of software testing principles through a certificate program. A certificate program is much more narrowly defined than a certification program such as the MSCSE (Microsoft Certified Systems Engineer) certification. A certificate normally means a person has obtained a very specific goal. Anyway, as part of my research, I reviewed the four primary software testing certifications that exist. They are the IIST CSTP (International Institute for Software Testing, Certified Software Test Professional), the QAI CSTE (Quality Assurance Institute, Certified Software Tester), the ASTQB CTFL (International/American Software Testing Qualifications Board, Certified Tester Foundation Level), and the ASQ CSQE (American Society for Quality, Certified Software Quality Engineer). I've put together a matrix that summarizes these four certifications. The bottom line is that they all target a different audience, and have different goals, with the one exception that they're all designed to generate revenue for their sponsoring companies and organizations. The image below is a snapshot of my matrix. You may need to click on the image to view it.
All these certifications have strengths and a whole lot of weaknesses. That's why we are putting together a lean, highly focused, relatively inexpensive, Certificate in Software Testing with Microsoft Technologies program.
03 maggio Rule Set ExtractionRecently I've been looking at the problem of rule set extraction. Actually, to be more accurate, I've been looking at a particular class of problems and I'm not exactly sure what these problems are called. Suppose you have a set of categorical data like this:
(Red, Small, Hot) -> c0
(Red, Small, Cold) -> c0 (Blue, Medium, Hot) -> c1 (Green, Large, Cold) -> c1 (Yellow, Large, Warm) -> c2 (Blue, Small, Hot) -> c2 The first tuple, or itemset, means that there is something which has an attribute of color = red, size = small, temperature = hot, and is assigned to category, or cluster c0. The problem I'm looking at is how to programmatically extract a set of rules from this data. For example, a human might conculde that:
if (color = Red) then cluster = c0
else if (size = Medium) then cluster = c1 else if (color = Gren) then cluster = c1 else cluster = c2 I've been looking for existing work in this area, but haven't found anything that matches this particular problem. The closet area I've found was pointed out to me by a colleague in Microsoft Research. That area is generally called Association Rules. However, Association Rules are slighty different because they look at all the associations within tuple attrbute values rather than the associations between the first n-1 attribute values, and some cluster or category. Anyway, it's a very interesting problem. |
|
|