<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5837736532401524761</id><updated>2012-02-16T03:35:12.920-08:00</updated><category term='PHP'/><category term='kickboxing'/><category term='rowing'/><category term='oxford'/><category term='maths'/><category term='PHP TestFest'/><category term='star wars'/><title type='text'>Josie's Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://jmessa.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5837736532401524761/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://jmessa.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>itsonrandom</name><uri>http://www.blogger.com/profile/13781576994831712961</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://bp0.blogger.com/_QNkBzQ_PHzk/SDmrmAl912I/AAAAAAAAAAM/Q9PZ9ejQn-0/S220/n511674458_424654_9230.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5837736532401524761.post-3210004127883828475</id><published>2010-01-25T15:24:00.000-08:00</published><updated>2010-01-25T16:07:14.868-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='star wars'/><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='rowing'/><category scheme='http://www.blogger.com/atom/ns#' term='maths'/><category scheme='http://www.blogger.com/atom/ns#' term='oxford'/><category scheme='http://www.blogger.com/atom/ns#' term='kickboxing'/><title type='text'>Start of HT 2010</title><content type='html'>Moved back to Oxford on &lt;span style="font-weight:bold;"&gt;Saturday &lt;/span&gt;of -1st week. Had a lot of fun moving the usual handful of boxes out of the car, over a few inches of ice and into my house trying to avoid the foot long icicles hanging from the guttering (welcome to student housing). Managed to arrive at exactly the same time as about 5 other people on my street which was great. As usual got Mum to buy me a steak in Cafe Rouge to help me survive the rest of term without raw meat. &lt;br /&gt;&lt;br /&gt;The rest of 0th week was spent in the library (from &lt;span style="font-weight:bold;"&gt;Sunday&lt;/span&gt; onwards) doing vac work and revising for collections. My wake up call was cycling to the river in the snow to cox the first boat. Training was going well although we only were able to get one VIII out and that had two novices in. Although the morning outings got me out of bed they also subjected everyone I happened to see to my complaints about not being able to feel my toes until about 9pm, when they were thoroughly warmed up after watching four episodes of House curled up in a blanket. &lt;br /&gt;&lt;br /&gt;Unfortunately Hilary Term didn't start so well. Had two collections on &lt;span style="font-weight:bold;"&gt;Friday&lt;/span&gt; which I did pretty poorly on. I'm entirely blaming that on feeling ill for most of &lt;span style="font-weight:bold;"&gt;Thursday&lt;/span&gt; (who knew snow was bad for you). By &lt;span style="font-weight:bold;"&gt;Sunday&lt;/span&gt; I felt much better, cured by running between the star wars marathon (all 6 films) happening in my basement and the library to get the last of the vac work finished. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Monday&lt;/span&gt; morning started with a 9am probability lecture, fun times! My diary looked horrific with about 16 hours worth of lectures scheduled. Considering I'm supposed to be taking 72 hours of lectures this term (which equates to 9 hours a week) I realised I needed to cut down on some of the courses. On &lt;span style="font-weight:bold;"&gt;Monday&lt;/span&gt; night I stole Mason (tutor) away from his dinner and we chatted about courses (unfortunately we were sat right at the bottom of the stairs leading to the dining hall. Subsequently most of the conversation was spent with me acknowledging half the college as they walked past, wondering why people were taking photos of the cat, and then trying to avoid the cat scratching my legs out). Was able to narrow it down to 80 hours which is far more sensible... &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Tuesday&lt;/span&gt; night was formal hall - classic lamb shank (which I'm really starting to get fed up of), with a dessert of football in the bar followed by a cheeseboard of probability served in the library, going on until I can't remember what hour of the morning (probably not that late considering my track record of this term so far). &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Wednesday&lt;/span&gt; turned out to be a pretty good evening. There was a surprise Captains' meeting (only a surprise since I apparently no longer process information in emails), so had to grab Dave (men's rowing captain) from the union and run down to a lecture theatre in Christ Church and listen to Pembroke and Christ Church whinge at each other for about an hour and a half. For me the meeting consisted of a lot of face-palming and wishing I had brought some work with me to make the time a bit more productive. On the way out, after locking all the captains inside the college gates, Dave asked if I'd eaten dinner yet. This evolved into us eating at Quod (which turns out is a really expensive restaurant on high street) and him paying for it. I wish being Boat Club captain was usually this decadent. On my walk home I bumped into all the freshers queuing outside NOPS (North Oxford Property Services) for the Jericho student housing release and did my Mother Theresa bit part by bringing out tea and hot water bottles. I have unfortunately not had either the mugs or the hot water bottles returned so I refuse to do anything charitable for the freshers again. &lt;br /&gt;&lt;br /&gt;The main event of &lt;span style="font-weight:bold;"&gt;Friday&lt;/span&gt; was getting soaked THROUGH semi-waterproof tracksuit bottoms and my sexy Somerville rowing splash jacket whilst cycling the 15 minute ride from my house to kickboxing - then attempting to box in soaking wet trackies. On arriving back home I was so exhausted that even climbing up the stairs to the warm shower was far too much effort. Naturally I solved the problem by curling up in the basement and watching House (this term's addiction, almost half way through season 2 and we only started watching it a week and a half ago). &lt;br /&gt;&lt;br /&gt;On &lt;span style="font-weight:bold;"&gt;Saturday&lt;/span&gt; the college had their first bop of Hilary term. For some reason it couldn't be held in college so I had to walk down to the OTHER END OF TOWN dressed as Evita. It was a good fun night, the venue was packed and everyone was in a good mood. Plenty of bad dancing was had. &lt;br /&gt;&lt;br /&gt;Highlight of the week was on &lt;span style="font-weight:bold;"&gt;Sunday&lt;/span&gt; (yesterday) when all of Somerville seemed to have a hangover. As the only one exempt from this rule I was able to observe and laugh, although had an equally unproductive day until the evening when I was finally able to start writing the PHP program for facebook (with half of the time working on it spent figuring out why eclipse was being so temperamental).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5837736532401524761-3210004127883828475?l=jmessa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jmessa.blogspot.com/feeds/3210004127883828475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5837736532401524761&amp;postID=3210004127883828475' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5837736532401524761/posts/default/3210004127883828475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5837736532401524761/posts/default/3210004127883828475'/><link rel='alternate' type='text/html' href='http://jmessa.blogspot.com/2010/01/start-of-ht-2010.html' title='Start of HT 2010'/><author><name>itsonrandom</name><uri>http://www.blogger.com/profile/13781576994831712961</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://bp0.blogger.com/_QNkBzQ_PHzk/SDmrmAl912I/AAAAAAAAAAM/Q9PZ9ejQn-0/S220/n511674458_424654_9230.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5837736532401524761.post-6753402772417307085</id><published>2008-05-25T10:59:00.000-07:00</published><updated>2008-05-25T11:29:47.629-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP TestFest'/><title type='text'>Lessons Learned in PHPT Writing</title><content type='html'>This is pretty much the same as the page from the PHP wiki (which can be found &lt;a href="http://wiki.php.net/qa/phptlessonslearned"&gt;here&lt;/a&gt;), less some stuff which has been added by other people.&lt;br /&gt;&lt;br /&gt;I decided to write this mainly because I won’t be writing tests as a full time job any more so am using this to pass the responsibility over to the new testers! But also with the impending TestFests and general focus on testing in the community thought it would be worthwhile to share my knowledge. Some of the points below are quite specific to the extensions that I’ve written tests for (array, ctype, dir, ereg, imap, mbstring, mysql and pcre), but hopefully will be useful for testing in general and should highlight the kind of things that should be focused on to produce a good test suite. If anyone wishes to add to, change or edit this list then please feel free, I’d be interested to see what other people have to say!&lt;br /&gt;&lt;br /&gt;I'd like to thank Zoe Slattery (zoe), Steve Seear (stevseea) and Robin Fernandes (robinf) for their help with producing this.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;General:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Keep basic tests basic: test a function with the minimum number of arguments, maximum number of arguments, and, if any flags or options can be set, each one of those (include any checks to ensure that they have been set).&lt;/li&gt;&lt;li&gt;Include files, although annoying for debugging reasons, save massive amounts of code reuse and keep tests clean and consistent.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;If using a function from an include file, write a comment explaining what the function is doing to save a reader’s time.&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;Use include files for variables that will change, for example passwords and names of databases and email servers. If using these, remember to generalise expected output.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Read the documentation, write tests that reflect what the documentation says the function should do.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;For example, in the directory functions the resource parameter in some functions is explained to be “opened using opendir”, try passing a resource opened with fopen(), this according to the documentation shouldn’t work (alas, it did).&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Use titles (in the –TEST– section) that explain what the test is actually doing! These should be &lt;span style="font-weight: bold;"&gt;one line only&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Tests should be intuitive, if something very complicated is happening separate a test out.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;If being non-intuitive is unavoidable, COMMENTS ARE USEFUL.&lt;/li&gt;&lt;li&gt;Lay tests out in an easy to read fashion, remember that other people might actually read them at some point.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;If the documentation says that behaviour is unpredictable, don’t write a test for that scenario.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Argument Types:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;When testing different data types for arguments that require integers, be careful of supplying resources. If no error message is returned, there is a chance that the resource has been converted to an integer which will be unpredictable, thus making the expected output impossible to create.&lt;/li&gt;&lt;li&gt;When testing arguments that relate to the length or offset of something, pass negative numbers, as well as numbers less and greater than the length.&lt;/li&gt;&lt;li&gt;If a function takes a resource as an argument, test different types of resources (file system, directory, database connection etc.) in case there is no type check.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Expected Output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;This list is quite specific to using EXPECTF, the same ideas apply to EXPECTREGEX though!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Run a test multiple times to check if the expected output needs to be generalised to accommodate for variable output.&lt;/li&gt;&lt;li&gt;Don’t put comments in the test explaining what the expected output should be, that’s what the expected output section is for :-).&lt;/li&gt;&lt;li&gt;Use echo statements to separate parts of the expected output (e.g. a counter if using iterations etc.)&lt;/li&gt;&lt;li&gt;Remember that the expected output has to reflect what will come out of a test if &lt;span style="font-weight: bold;"&gt;everything is working&lt;/span&gt;. For example a test with a statement conditionally echoed out that has not been included in the expected output saying that something is not available, with a comment next to it saying “don’t fail if this happens” is nonsensical, the test will fail if this happens as the string is not in the expected output.&lt;/li&gt;&lt;li&gt;If var_dumping a string where some of the string is generalised (i.e. replaced with %d/%s etc), check the string length is not also variable.&lt;/li&gt;&lt;/ul&gt;  &lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;string(%d) "The next bit might vary in length: %s"&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Change numbers generated in resources and objects to %d.&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;object(C)#%d (1) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;  ["p"]=&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;  bool(true)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;resource(%d) of type (stream)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;casting a resource to a string: you don’t know how many digits the number will be, so character count has to be %d too!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;string(%d) "Resource id #%d"&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Try to write the expected output yourself, instead of copying and pasting from a console. This ensures that you don’t miss any odd/unexpected behaviour.&lt;/li&gt;&lt;li&gt;Watch out for line endings on different platforms and how that effects the character length of a string&lt;/li&gt;&lt;li&gt;Avoid using %a unless it &lt;span style="font-weight: bold;"&gt;really &lt;/span&gt;is unavoidable. I mean &lt;span style="font-weight: bold;"&gt;REALLY &lt;/span&gt;unavoidable.&lt;/li&gt;&lt;li&gt; Watch out for error messages in the expected output:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Change the file location to %s&lt;/li&gt;&lt;li&gt;Line numbers should be changed to %d, though this can mean bugs don’t get noticed (for example all errors saying “on line 0”). If leaving the line number in, ensure it’s the right one!&lt;/li&gt;&lt;li&gt;Some errors are platform specific, if they’re being generated using &lt;span style="font-family:courier new;"&gt;strerror(errno)&lt;/span&gt; in the source code then change the error to %s.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Specific Extensions:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;These are specific to extensions I have tested, but could probably be used in other extensions too.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;MBString:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;‘unexpected’ behaviour can come from not remembering byte length vs character length in strings.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;e.g. in mb_ereg the byte length of a matched part of a string is returned instead of the character length, so for example when 15 multibyte characters are matched, mb_ereg returned int(35). (see mb_ereg_basic.phpt).&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;base64 encode any multibyte strings that appear in the expected output.&lt;/li&gt;&lt;/ul&gt;       &lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Anything requiring an external server (e.g. MySQL, IMAP):&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt; Use an include file where users can set their own username, password and server name as variables, then ensure that you use the variables throughout the tests.&lt;/li&gt;&lt;li&gt;   Whenever any of these appear in the expected output, remember to replace them with %s (if using EXPECTF).&lt;/li&gt;&lt;li&gt;If something doesn’t appear to be working as expected, it could be that the server you’re using doesn’t support this functionality (to save bogus bugs).&lt;/li&gt;&lt;li&gt;If possible, test tests on more than one server before committing.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Test Case Generator:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This script was written by Zoe Slattery (thank you!) and can be found in the PHP 5_3 source code in &lt;span style="font-style: italic;"&gt;scripts/dev/generate_phpt.php&lt;/span&gt;. Although it’s in the 5_3 source code, I think I’m right in saying that it can be used to create tests for &lt;span style="font-weight: bold;"&gt;all&lt;/span&gt; versions of PHP. I use it for all the tests I have written and have found it to be incredibly useful! The basic format of it is that you pass a function name and a type of test (either basic, error or variation) and it will generate a template for the test. Below is how I have it set up on my machine (windows), and how I use it.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Use on command Line:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;php.exe generate_phpt.php –h&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;will give a good overview of how to use the test case generator, there are things that I set every time I use it so have that in a batch file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;gen.bat file:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;cd &amp;lt;place to store generated tests&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;php.exe &amp;lt;location of generate_phpt.php script&amp;gt; -s &amp;lt;location of source code&amp;gt; -f %*&lt;/span&gt;&lt;br /&gt;&lt;place to="" store="" generated="" tests=""&gt;&lt;location of="" php="" script=""&gt;&lt;location of="" source="" code=""&gt;&lt;span style="font-weight: bold; color: rgb(255, 204, 102);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I then type the function name and the type of test I want, e.g.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;gen.bat array_key_exists –b&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This will generate a basic test for array_key_exists. All I need to do now is fill out the EXPECTF section of the file!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Variation tests:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);font-family:courier new;" &gt;gen.bat array_key_exists –v&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;will generate variation tests. There will be one for each of the functions argument and an empty test. The numbered variations will iterate over an array of different data types and pass them as an argument, these tests are very useful! Again all that needs doing with these is changing the title (in the --TEST-- section), add a comment explaining what the test is doing and filling out the EXPECTF section. With the blank variation test is a template for any other variation tests the function needs.&lt;/location&gt;&lt;/location&gt;&lt;/place&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5837736532401524761-6753402772417307085?l=jmessa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jmessa.blogspot.com/feeds/6753402772417307085/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5837736532401524761&amp;postID=6753402772417307085' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5837736532401524761/posts/default/6753402772417307085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5837736532401524761/posts/default/6753402772417307085'/><link rel='alternate' type='text/html' href='http://jmessa.blogspot.com/2008/05/lessons-learned-in-phpt-writing.html' title='Lessons Learned in PHPT Writing'/><author><name>itsonrandom</name><uri>http://www.blogger.com/profile/13781576994831712961</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://bp0.blogger.com/_QNkBzQ_PHzk/SDmrmAl912I/AAAAAAAAAAM/Q9PZ9ejQn-0/S220/n511674458_424654_9230.JPG'/></author><thr:total>0</thr:total></entry></feed>
