<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-21220738</id><updated>2007-06-04T14:01:21.872-07:00</updated><title type='text'>Everyone Else Is Doing It...</title><link rel='alternate' type='text/html' href='http://chatley.com/blog/'></link><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default?start-index=26&amp;max-results=25'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default'></link><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://chatley.com/blog/atom.xml'></link><author><name>Robert Chatley</name></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>26</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-21220738.post-7121906054979759507</id><published>2007-04-01T11:59:00.000-07:00</published><updated>2007-04-01T08:54:11.292-07:00</updated><title type='text'>commons.testing</title><content type='html'>There are lots of different testing tools and frameworks out there. Maybe too many. We end up having to use a whole bunch of different tools to test different parts of our projects. In working on LiFT, we've found that for various reasons we're currently tied in to JUnit, and it's quite a lot of work to create a version for TestNG or other frameworks, or to integrate our acceptance tests with jMock etc. Because of these problems we're looking forward to the &lt;a href="http://www.mockobjects.com/2007/03/announcing-commonstesting-and.html"&gt;release of commons.testing&lt;/a&gt;, a framework agnostic API for writing tests. This upcoming release was the cause of a lot of buzz at the &lt;a href="http://www.spaconference.org/"&gt;SPA conference&lt;/a&gt; last week. &lt;br /&gt;&lt;br /&gt;With its extensive XML configuration support, commons.testing also aims to remove the dependency on writing code, allowing tests to be written by non-programmers. Again very well aligned with LiFT's goals. Look out for more information on this all-encompassing framework soon.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2007/04/commonstesting.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/7121906054979759507'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/7121906054979759507'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-2322985997643086028</id><published>2007-02-11T12:32:00.000-08:00</published><updated>2007-02-11T12:29:56.697-08:00</updated><title type='text'>Push Web</title><content type='html'>It seems that as the amount of content on the web grows, it becomes less and less efficient to surf around and look for interesting things. Where previously people would have their lists of sites that they would visit regularly to catch up on updates, more and more people are now setting up subscriptions and feeds so that they don't have to take the time to go and look if there is anything new.&lt;br /&gt;&lt;br /&gt;Rather than going out hunting for new content, we want new content to come to us. We want it to be a push rather than a pull model. However, even with RSS feeds and the like, at the moment we are still polling our favourite sites at regular intervals, it's just that we have a machine to do it for us. Although we appear to be getting content pushed to us, we aren't really.&lt;br /&gt;&lt;br /&gt;I think that the next step for the web is some sort of real push messaging for content, so in my browser I just set up a list of things that I'm interested in, and when new stuff is available, and I'm connected, it is piped to my machine for me to read. One of the things I read recently which reinforced this feeling was Tibco's &lt;a href="http://getahead.ltd.uk/dwr/tibco"&gt;sponsorship&lt;/a&gt; of the development of DWR. DWR is a framework for working with AJAX in web applications, and Tibco one of the big name vendors of messaging products. &lt;br /&gt;&lt;br /&gt;Also, with the increase in the numbers of mobile devices used for internet access, push would seem to be a good fit. Connectivity for a mobile device is at best intermittent, and currently if I want to look at the news headlines when I'm out of signal range, I'm stuck. With a push model, my device can be updated asynchronously as I walk around in and out of signal areas, so I should have some reasonably fresh data whenever I look. It would be a substantial change to the way that the web has tradionally worked to push content to the browser, but I can feel it coming.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2007/02/push-web.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/2322985997643086028'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/2322985997643086028'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-116785950517513735</id><published>2007-01-03T13:08:00.000-08:00</published><updated>2007-01-03T13:25:05.190-08:00</updated><title type='text'>New Year, New Calendar</title><content type='html'>In planning our iteration's work at the beginning of this week, we used something simple but effective to focus on how many people were available, and who could work on what when. We drew up a simple calendar on a whiteboard showing when each person would be on holiday, and when people would be out of the office (at client meetings etc).&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;img src="http://chatley.com/images/cal01.jpg" /&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;The effect that this had was that we were clearly able to think about estimating and committing to work suitable for the people available. For example, we can see that Raymond is not back from his Christmas break until Thursday. There were some tasks that he has the most relevant skills for, so our customer agreed that we should move these to next week, instead prioritising things that Kylie could start on, and pair with Raymond when he gets back. The graphical representation gave us something that clearly showed our resource constraints, and it clearly provided a basis for prioritisation that was easily accessible to the customer.&lt;br /&gt;&lt;br /&gt;It was also easy for us to see how many person days we had available, and to know when the amount of work planned for the week was more than we could commit to. We also used the calendar to record release dates and other pieces of work that need to be done on fixed days. I like the simplicity and the focus that the calendar brings. I think we'll be keeping it.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2007/01/new-year-new-calendar.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/116785950517513735'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/116785950517513735'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-116725311671589488</id><published>2006-12-27T21:00:00.000-08:00</published><updated>2006-12-27T12:58:36.770-08:00</updated><title type='text'>Intentional Programming</title><content type='html'>So, it's been a while since I last posted anything here. It's been a busy few months and I'm just finding a little bit of time to catch up in the Christmas break. One of the major things that happened in the last couple of months was &lt;a href="http://www.xpday.org"&gt;XPDay&lt;/a&gt; which &lt;a href="http://www.xpday.org/organisation.php"&gt;we&lt;/a&gt; organised in London. The conference sold out (for the sixth year running) and thanks to everyone who came along and participated it was a great event.&lt;br /&gt;&lt;br /&gt;One of the sessions that I enjoyed the most at the conference was Awesome Acceptance Testing presented by &lt;a href="http://dannorth.net/"&gt;Dan North&lt;/a&gt; and &lt;a href="http://joe.truemesh.com"&gt;Joe Walnes&lt;/a&gt;. Dan and Joe presented a number of different approaches to acceptance testing, and talked about what acceptance testing means for different people in the development process - often these are the same people wearing different hats at different times - customers, analysts, testers and developers. They distilled the subject to five key themes. To do acceptance testing effectively, you need: automation, a harness, a vocuabulary, a syntax, and to be capturing intent.&lt;br /&gt;&lt;br /&gt;This last point seems very important, and in fact links together a number of different themes at the conference, and a number of different open source projects that are currently under development in the area of testing. We are trying to build tests that express their intent. The clearer they are about how the system is supposed to behave, the more use they are as a specification, and the easier it is for customers to validate them. How do we know that we are writing the right tests unless we can check them with the customer?&lt;br /&gt;&lt;br /&gt;Also at XPDay, Tamara Petroff and I ran a workshop session on &lt;a href="http://chatley.com/blog/2006/05/literate-functional-testing.html"&gt;literate testing&lt;/a&gt;. The idea here was for customers and developers to work together to create tests for a given scenario that expressed their intention clearly enough that there could be a discussion between customer and developer focussed on the test. However, we provided a structure which meant that the resulting tests were of a form that could be readily automated, making them of direct use to the development team. Our literate testing work has resulted in the release of the &lt;a href="https://lift.dev.java.net"&gt;LiFT&lt;/a&gt; framework which allows tests to be written in Java that read as natural language. At the moment the framework focusses on the web domain, but one of the things that we experimented with in the workshop was how tests for different domains might be written while maintaining the same overall structure.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;img src="http://chatley.com/images/liftgroup.jpg" /&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Groups worked together assembling tests usings decks of cards that we provided with various keywords printed on them. The also had some blank cards available to that they could extend the vocubulary when they needed to. This is important, as to express intent clearly, we need to be able to write our tests using the language of the domain that we are working in. If we are restricted to a fixed vocabulary by our test framework, this is very limiting, and often leads to tests being written that talk about the technology used to solve the problem (e.g. user interface widgets) rather than activity that the user is trying to carry out with the system.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;img src="http://chatley.com/images/liftcards.jpg" /&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;One of our exercises involved writing acceptance tests for a report to be produced in the form of a spreadsheet. Most of the printed cards that we had provided were tailored to the web domain, so the teams had to produce more cards with words to describe the spreadsheet domain. From the results (in the picture above) we can see that the parts of the vocabulary to do with assertion could be reused from one domain to another, but the types of things present in each domain were different, and this is where new cards needed to be written. The pattern of printed and handwritten cards in columns struck me as highlighting the structure that is provided by the test framework. This helps to guide us towards creating tests that are automatable, but at the same time giving us the freedom in vocubulary to express our intent.&lt;br /&gt;&lt;br /&gt;While we are discussing this topic, there are a couple of other projects worth mentioning. The &lt;code&gt;assertThat&lt;/code&gt; syntax that we use in LiFT originally came from Joe Walnes, and was built into &lt;a href="http://www.jmock.org"&gt;jMock&lt;/a&gt;. Not the matching/constraints part of jMock has been extracted into its own extensible library, &lt;a href="http://code.google.com/p/hamcrest/"&gt;Hamcrest&lt;/a&gt;. This has recently seen its &lt;a href="http://weblogs.java.net/blog/tomwhite/archive/2006/12/hamcrest_1.html"&gt;1.0 release&lt;/a&gt; and is well worth checking out.&lt;br /&gt;&lt;br /&gt;One of the reasons for the release of Hamcrest was the upcoming (sometime real soon now, apparently) release of an RC1 version of &lt;a href="http://cvs.jmock.codehaus.org/browse/jmock/jmock2/"&gt;jMock2&lt;/a&gt;. Having used jMock2 for a couple of weeks now, there are a few things that make it feel so much better than the original jMock. They're difficult to describe, but it's now much easier to write your test first and use your IDE to reactively complete/generate the code you need to make the test pass. jMock2 also uses Hamcrest, and focuses on providing a syntax that makes tests easy to read.&lt;br /&gt;&lt;br /&gt;I can see intentional programming becoming a theme for 2007 (although I probably don't mean exactly the same thing that &lt;a href="http://www.intentionalsoftware.com/"&gt;Charles Simonyi&lt;/a&gt; does).</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/12/intentional-programming.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/116725311671589488'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/116725311671589488'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-116215939145387081</id><published>2006-10-29T13:44:00.000-08:00</published><updated>2006-10-29T14:03:11.490-08:00</updated><title type='text'>PHP - the most postmodern of programming languages?</title><content type='html'>Recently I've been doing a bit of maintenance work on a few websites written in PHP. I've never really been a PHP programmer, but I can read existing code and search for examples of things I want to do on the web. One way or the other I can usually get to something that works, although it might involve some trial and error, and I doubt that what I create is the most elegant solution to the problem. While doing this it struck me that I know very few people who would profess to be PHP programmers, but a lot of people who have &amp;quot;done some PHP&amp;quot; - many people who work with PHP in the same way that I do. You know enough programming concepts to envisage what should be possible, and you can copy, paste and edit existing code to come up with a solution. &lt;br /&gt;&lt;br /&gt;This seems very much in line with some of the things that James Noble and Robert Biddle talked about in their paper &lt;a href="http://www.mcs.vuw.ac.nz/comp/Publications/CS-TR-02-9.abs.html"&gt;Notes on Postmodern Programming&lt;/a&gt;. Postmodern programming takes the view that things are often not designed and implemented in a consistent way from scratch, but more often created by integrating and reusing existing software components, or bits of them, and glueing them together to make something that works. This is a topic that will be explored further at &lt;a href="http://www.bcs-spa.org/pomopro.html"&gt;PoMoPro&lt;/a&gt;, the first international conference on postmodern programming, to be held in London on the 25th of November.&lt;br /&gt;&lt;br /&gt;Although I can see that a lot of software projects do follow these themes of combining various existing parts to produce a whole, and that there is a certain satisfaction and pragmatism to rigging something up as fast as possible that does the job, I have to say that I am probably something of a modernist at heart. I have a better feeling about a project when the overall design is consistent and elegant. I prefer those clean lines. But I suppose that this is horses for courses, and in some cases the best thing to do is bolt together what you can find, in other cases you might be better served by creating an overarching design.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/10/php-most-postmodern-of-programming.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/116215939145387081'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/116215939145387081'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115939272426559053</id><published>2006-09-27T22:28:00.000-07:00</published><updated>2006-09-27T14:32:04.273-07:00</updated><title type='text'>XPDay6 Registration Open</title><content type='html'>Registration is now open for &lt;a href="http://www.xpday.org"&gt;XP Day 6&lt;/a&gt; in London on November 27-28. The programme is also now available on the website. There is a great set of sessions spread over two days on various aspects of agile development, from the hard core technical to the much more people focussed. Places are limited, and always sell out quickly, so make sure to register early.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/09/xpday6-registration-open.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115939272426559053'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115939272426559053'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115886466038028669</id><published>2006-09-21T11:39:00.000-07:00</published><updated>2006-09-21T11:51:00.496-07:00</updated><title type='text'>LiFT: Literate Functional Tests go open source</title><content type='html'>I've written a fair bit about &lt;a href="http://chatley.com/blog/2006/05/literate-functional-testing.html"&gt;literate testing&lt;/a&gt; in the past. With some support from my current employer &lt;a href="http://www.kizoom.com"&gt;Kizoom&lt;/a&gt;, the framework I have been working on has now been published as open source on java.net. We've called it LiFT.&lt;br /&gt;&lt;br /&gt;Here is the &lt;a href="https://lift.dev.java.net"&gt;LiFT page on java.net&lt;/a&gt;. Please try it out and let us know if you have any feedback.&lt;br /&gt;&lt;br /&gt;For more background, see the &lt;a href="http://video.google.com/videoplay?docid=1505469784301926538&amp;q=chatley+white&amp;hl=en"&gt;video&lt;/a&gt; of the presentation &lt;a href="http://tiling.org"&gt;Tom White&lt;/a&gt; and I gave at the Google London Test Automation Conference.&lt;br /&gt;&lt;br /&gt;Thanks to all who have contributed code and ideas to get us this far. We hope there is a bright future for LiFT.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/09/lift-literate-functional-tests-go-open.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115886466038028669'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115886466038028669'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115851802101187071</id><published>2006-09-17T19:23:00.000-07:00</published><updated>2006-09-17T11:33:41.020-07:00</updated><title type='text'>Google London Test Automation Conference</title><content type='html'>The conference was held on the 7th and 8th of September in London. There was a wide range of talks over two days on various aspects of automated testing. In London, Google focus on mobile development and it was heartening to hear that they also think testing applications to be accessed through a large number of different devices is a hard problem, and that they don't have all the answers. There was an interesting talk on performance testing from Goranka Bjedov of Google. She advocated the  use of open source tools like Grinder and JMeter. There were other interesting talks on testing ajax applications (Joe Walnes and Adam Connors), testing different browsers (Jason Huggins) and deployment environments (Steve Loughran), and testing wireless networks (Karl Garcia).&lt;br /&gt;&lt;br /&gt;Tom White and I gave a talk about the development and use of our framework for Literate Functional Testing. This generated a lot of interest. Thanks to everyone for their comments and questions. We hope to be open sourcing the project soon.&lt;br /&gt;&lt;br /&gt;All of the talks were recorded, and are now &lt;a href="http://video.google.com/videosearch?q=label:ltac"&gt;available online on Google video&lt;/a&gt;. The slides from the literate testing talk are also available &lt;a href="http://chatley.com/presentations/literate-functional-testing.pdf"&gt;here&lt;/a&gt; as a pdf file.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/09/google-london-test-automation.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115851802101187071'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115851802101187071'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115282466793155738</id><published>2006-07-13T13:52:00.000-07:00</published><updated>2006-07-13T14:04:27.953-07:00</updated><title type='text'>Conference on Test Automation - Registration Open</title><content type='html'>Registration is now open for the Conference on Test Automation, to be held in London in September. The &lt;a href="http://www.google.co.uk/intl/en/events/londontesters/speakers.html"&gt;programme of speakers&lt;/a&gt; looks very interesting - I'm particularly looking forward to hearing what Rick Mugridge, Michael Ernst and Nigel Daley have to say. There's also a talk on testing on mobile handsets which sounds pretty relevant to things that I'm working on at the moment.&lt;br /&gt;&lt;br /&gt;In perhaps typical style, Google have adopted a slightly unusual approach to the registration process for the conference. If you'd like to attend, simply draft a missive in 400 words or less describing &amp;quot;what you expect to learn at this conference and the specific issues you'd like the speakers to address&amp;quot;. Post your application in the &lt;a href="http://services.google.com/events/londontesters"&gt;online form&lt;/a&gt;. Hope to see you there.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/07/conference-on-test-automation.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115282466793155738'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115282466793155738'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115153053982926125</id><published>2006-06-28T22:26:00.000-07:00</published><updated>2006-06-28T14:35:39.840-07:00</updated><title type='text'>XP Day 6</title><content type='html'>The details of this year's &lt;a href="http://www.xpday.org"&gt;XP Day conference&lt;/a&gt; have been announced. The conference will take place on 27th-28th November, in London, UK. If the past years are anything to go by, this should be an excellent event. The style of the conference is such that most of  the sessions actively encourage participation by the delegates, normally through some sort of interactive exercise. This is a great way to learn, and to get to know new people. &lt;br /&gt;&lt;br /&gt;I am helping to organise the programme for this year's conference, and we are now looking for people to submit suggestions for sessions they would like to run. Full details of what we are looking for, and instructions for how to submit, can be found in the &lt;a href="http://www.xpday.org/wiki/index.php/Call_For_Proposals"&gt;call for proposals&lt;/a&gt;. The closing date for submissions is August 14th, so get thinking.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/06/xp-day-6.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115153053982926125'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115153053982926125'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115134776855663108</id><published>2006-06-26T19:40:00.000-07:00</published><updated>2006-06-26T12:02:15.823-07:00</updated><title type='text'>Update - generics puzzles</title><content type='html'>After my post yesterday, &lt;a href="http://www.zonetora.co.uk"&gt;Tristan Allwood&lt;/a&gt; and &lt;a href="http://www.nicholascameron.co.uk/"&gt;Nick Cameron&lt;/a&gt; both wrote to offer some help. When you want a list of things that implement both interface A and interface B, the syntax that you need is: &lt;code&gt;List&amp;lt;T extends A &amp;amp; B&amp;gt;&lt;/code&gt;. Yes, that's an ampersand. Ugly isn't it. To make matters worse, this syntax doesn't mix well with wildcards, so you can't write &lt;code&gt;List&amp;lt;? extends A &amp;amp; B&amp;gt; &lt;/code&gt;. Instead you have to write &lt;code&gt;&amp;lt;T extends A &amp;amp; B&amp;gt; void m(List&amp;lt;? extends T&amp;gt;) { ... } &lt;/code&gt;.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/06/update-generics-puzzles.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115134776855663108'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115134776855663108'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115126492250951074</id><published>2006-06-25T20:42:00.000-07:00</published><updated>2006-06-25T12:48:42.526-07:00</updated><title type='text'>More generics puzzles</title><content type='html'>This week I had a couple of interesting discussions with people about some particular points of programming with Java generics. The first case was that a developer wanted to write a method that processed a list of objects that implemented two interfaces. He wasn't concerned with the actual class of the objects, just that they implemented the two interfaces in question. This seemed to be a case for the use of wildcards, where we can specify a method as taking a paramater that is, say, a &lt;code&gt;List&amp;lt;? extends A&amp;gt;&lt;/code&gt;. However, it doesn't seem to be possible to write something like &lt;code&gt;List&amp;lt;? extends A, B&amp;gt;&lt;/code&gt;, even when A and B are interfaces rather than classes.&lt;br /&gt;&lt;br /&gt;Some might say that a method should only act on an object through one of its interfaces, and that any processing using the other interface should be  encapsulated in a separate method, but this is a matter of design, and it does not seem that it should be being enforced by the type system. Also, it seems unlikely that this is the reason that Java does not support this.&lt;br /&gt;&lt;br /&gt;In the end, the best solution we could come up with was to create an interface C that extended A and B, and to make the objects to be processed implement this interface instead. The source of these classes happened to be under our control so we could do this, but it didn't seem like an optimal solution, and there are many cases where it could not be used.&lt;br /&gt;&lt;br /&gt;The second case, was where a different developer was writing a unit test using &lt;a href="http://www.jmock.org"&gt;jMock&lt;/a&gt; mock objects for the collaborators of the class under test. In this case, this meant that he needed to mock a generic class, as the class under test had a setter method that takes a particular instantiation of the generic. So we had code along the lines of:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class X {&lt;br /&gt;  setK(K&amp;lt;String&amp;gt; k) {&lt;br /&gt;    ...&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class TestX extends MockObjectTestCase {&lt;br /&gt;  void test() {&lt;br /&gt;    X x = new X();&lt;br /&gt;    Mock mockK = mock(K.class);&lt;br /&gt;    x.setK(mockK.proxy());&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The first thing to notice is that we cannot write &lt;code&gt;mock(K&amp;lt;String&amp;gt;.class)&lt;/code&gt;. See an &lt;a href="http://chatley.com/blog/2006/01/java-generics-niggle.html"&gt;earlier post&lt;/a&gt; for an explanation of why not. Therefore we have to mock K.class. First of all, we wondered whether this would work, especially as we were using the cglib variant of the jMock library, but in fact it did. The interesting part is that in the above code, we have to cast the result of &lt;code&gt;mockK.proxy()&lt;/code&gt; in order for it to compile. The most obvious thing is to cast it to a K&amp;lt;String&amp;gt;. But, using Eclipse, we get a warning that says that our cast is "actually checking against the erased type". This is true, as after compilation the generic type information is not present, so there is no way to check this cast at runtime.&lt;br /&gt;&lt;br /&gt;If we make the cast a bit less specific, and just cast to a K, then we get a different warning, saying that we need an unchecked conversion to conform to the signature of the method that we are calling. It seems there is no way we can win, and the only way to keep Eclipse happy is to add an annotation to the method to suppress the warnings - not ideal.&lt;br /&gt;&lt;br /&gt;To some extent, these problems were caused by the fact that jMock is written using the Java 1.4 API, and so does not have inbuilt support for generics, but this is not the only cause, and it seems to be a common case that generic code is interwoven with older, non-generic code. These sorts of examples certainly show that the Java generics, and the supporting type rules, can be somewhat puzzling.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/06/more-generics-puzzles.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115126492250951074'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115126492250951074'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115092620540837145</id><published>2006-06-21T22:31:00.000-07:00</published><updated>2006-06-21T14:43:25.416-07:00</updated><title type='text'>London Test Automation Conference</title><content type='html'>A well-known &lt;a href="http://www.google.com"&gt;search engine&lt;/a&gt; is hosting the &lt;a href="http://googleresearch.blogspot.com/2006/04/our-conference-on-automated-testing.html"&gt;London Test Automation Conference&lt;/a&gt; in September. &lt;a href="http://tiling.org"&gt;Tom&lt;/a&gt; and I were pleased to be invited to present our experiences using the literate testing style that we have been working on recently. Hopefully it'll be an interesting event, although the full programme has yet to be announced, so we don't know who else will be there yet.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/06/london-test-automation-conference.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115092620540837145'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115092620540837145'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115040308472352904</id><published>2006-06-15T13:19:00.000-07:00</published><updated>2006-06-15T13:24:44.733-07:00</updated><title type='text'>Carnival of the Agilists</title><content type='html'>Kevin Rutherford has been putting together a fornightly round-up of agile topics being discussed in the blogosphere, which he calls &lt;a href="http://silkandspinach.net/blog/2006/06/carnival_of_the_8.html"&gt;Carnival of the Agilists&lt;/a&gt;. We got a mention in the current edition, thanks Kevin. There's also some interesting stuff from Liz Keogh and Joakim Karlsson amongst others.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/06/carnival-of-agilists.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115040308472352904'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115040308472352904'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-115032301796788170</id><published>2006-06-14T14:53:00.000-07:00</published><updated>2006-06-14T15:10:17.980-07:00</updated><title type='text'>Brian Marick's Sentence Style Tests</title><content type='html'>Brian Marick has also been thinking about &lt;a href="http://www.testing.com/cgi-bin/blog/2006/06/09#mock-style"&gt;making tests more readable&lt;/a&gt; (also inspired by &lt;a href="http://www.jmock.org"&gt;jMock&lt;/a&gt;). He &lt;a href="http://www.testing.com/cgi-bin/blog/2006/06/13#updates"&gt;mentions&lt;/a&gt; what Tom and I have been writing about (thanks Brian). His tests are perhaps more readable because a lot of the functions are written to explicitly test particular cases, e.g. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;page.main_text.should_have_no_list_named(:visits). &lt;br /&gt;                   should_have_no_list_named(:audits). &lt;br /&gt;                   and_should_have_a_help_popup_named(:patient_display_page)&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;so the logic or quantification is combined with the noun he is trying to match, in the same statement. We have tried to construct more general building blocks, which means we tend to have rather more nesting of clauses. Also, Brian benefits from the fact that he is using Ruby rather than Java, so the syntax is somewhat less cumbersome.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/06/brian-maricks-sentence-style-tests.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115032301796788170'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/115032301796788170'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-114911317120060503</id><published>2006-05-31T14:45:00.000-07:00</published><updated>2006-05-31T15:06:11.223-07:00</updated><title type='text'>Taking things into consideration</title><content type='html'>I've been working on a &lt;a href="http://weblogs.java.net/blog/tomwhite/archive/2006/05/literate_progra_1.html"&gt;new style of writing tests&lt;/a&gt; for a while. One of thing we're finding at the moment, is that you often want to narrow down the available objects to pick out a particular part, and then make a number of assertions about this same part.&lt;br /&gt;&lt;br /&gt;For example, you might be modelling a garden, and you want to write some tests concerning a certain set of plants, maybe those that are yellow. Using the style that &lt;a href="http://tiling.org"&gt;Tom White&lt;/a&gt; and I have discussed before, we could write something like:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;assertThat(garden, has(flowers().coloured(yellow)));&lt;br /&gt;assertThat(garden, has(flowers().in(flowerbed()).coloured(yellow)));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This checks that there exist some flowers that are yellow. But what if we want to check that all the flowers in the flowerbed are yellow? We've come up with the idea of a &lt;em&gt;consideration&lt;/em&gt;. We use a &lt;code&gt;considering(...)&lt;/code&gt; clause to refine the scope of our assertion, and have also created an &lt;code&gt;assertThatAll()&lt;/code&gt; assertion to take into account the universal quantification. The results look like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;considering(flowerbed());&lt;br /&gt;assertThatAll(flowers(), areColoured(yellow));&lt;br /&gt;assertThatAll(flowers(), areInBloom());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I think this will be subject to some refinement as we put it to use in more places, and we'll see whether or not it is useful. We've certainly found a few places so far where we want to check a property for a set of objects, and writing a loop isn't very in keeping with our &lt;a href="http://www-cs-faculty.stanford.edu/~uno/lp.html"&gt;literate&lt;/a&gt; style.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/05/taking-things-into-consideration.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/114911317120060503'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/114911317120060503'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-114850721467354138</id><published>2006-05-24T14:39:00.000-07:00</published><updated>2006-05-24T14:46:54.676-07:00</updated><title type='text'>Tying Tests to Requirements</title><content type='html'>On my current project, we've got a large requirements document, with a lot of numbered requirements. We want to be sure that we've covered all the requirements in our automated test suite. Rather than going through by hand checking off tests against the list, we had the idea of marking each test with its corresponding requirements, in the code.&lt;br /&gt;&lt;br /&gt;As we're working with Java 5, it seemed appropriate to do this using Java &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html"&gt;annotations&lt;/a&gt;. We created an annotation that can be applied to test methods, parameterised by the number.&lt;br /&gt;&lt;br /&gt;Even better, we were able to use the &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/apt/"&gt;annotation processing tool&lt;/a&gt; to run over our test code, and produce a report of which tests test which requirements, and which requirements are not covered by any of our test cases. When I add a test, I can quickly regenerate the report. I have a feeling this is going to be very useful.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/05/tying-tests-to-requirements.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/114850721467354138'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/114850721467354138'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-114850664707422319</id><published>2006-05-24T14:30:00.000-07:00</published><updated>2006-05-24T14:37:27.093-07:00</updated><title type='text'>Literate Functional Testing</title><content type='html'>For a while now, I've been working on some ideas about writing automated tests that are readable even for non-programmers. This makes it easier to write tests in language that is understood by users or customers, making sure that requirements are agreed.&lt;br /&gt;&lt;br /&gt;I've been working on this with &lt;a href="http://tiling.org"&gt;Tom White&lt;/a&gt;, who has written up some good posts on the subject, talking about our use of &lt;a href="http://weblogs.java.net/blog/tomwhite/archive/2006/05/literate_progra_1.html"&gt;constraints&lt;/a&gt;, and our ideas about using &lt;a href="http://weblogs.java.net/blog/tomwhite/archive/2006/05/more_literate_p.html"&gt;anaphora&lt;/a&gt;, on his blog on java.net.&lt;br /&gt;&lt;br /&gt;I really meant to write these up myself, but haven't had time for much blogging lately. Thanks to Tom for his articles.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/05/literate-functional-testing.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/114850664707422319'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/114850664707422319'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-113987100670085893</id><published>2006-02-13T22:49:00.000-08:00</published><updated>2006-02-13T14:50:06.703-08:00</updated><title type='text'>On another note</title><content type='html'>A couple of weekends ago I was pleasantly surprised to bump into &lt;a href="http://stevef.truemesh.com"&gt;Steve Freeman&lt;/a&gt; at &lt;a href="http://www.rehearsal-orchestra.org"&gt;a very English institution&lt;/a&gt;. Steve came up with a parallel between the way that orchestral players mark their parts in pencil, and the way people comment their code. With orchestral scores, each player and conductor has their own interpretation of the piece. They often mark their parts in pencil to remind them of changes of tempo, changes of key, or when the pages need turning quickly. As sets of parts get passed from one player or orchestra to another, the amount of pencil tends to increase, often obscuring the original information. It is normally a relief to see a nice clean part with little or no pencil, just the notes and directions as written by the composer. Removing the clutter gives time and space to read and process all of the information on the page, without confusion, contradiction or duplication of information.  &lt;br /&gt;&lt;br /&gt;People often encourage thorough commenting of code, to explain to other developers what it does, and how it works. Steve and I reckoned that we would much rather see clear, well written code with no comments, than the verbose and largely unhelpful comments that one often sees. Then when you do see a comment, you know to pay particular attention to it. We really want to see the notes underneath the pencil, not be distracted by scribbles.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/02/on-another-note.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113987100670085893'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113987100670085893'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-113987056962280261</id><published>2006-02-13T22:30:00.000-08:00</published><updated>2006-02-13T14:42:49.843-08:00</updated><title type='text'>Drawing Parallels</title><content type='html'>Recently I've been reading a bit about Neuro Linguistic Programming (NLP). I haven't got too deeply into it, but it's generally a set of theories about the way that people think, communicate, learn and perceive the world around them. For example, some people think about things mostly in a visual way, whereas others prefer to use sounds or feelings to represent their thoughts internally. The idea is that by learning about the different representation systems, and how to tell which ones people favour, you can tailor your words and actions to communicate with them more effectively.&lt;br /&gt;&lt;br /&gt;The particular book I am reading wraps this up in a self-help, being a more effective person, achieve your life goals type of way, but one thing struck me. The book describes the essence of NLP, and being an "effective person", as 1) know what you want; have a clear idea of your outcome in any situation, 2) be alert and keep your senses open so that you know what you are getting, 3) have the flexibility to keep changing what you do until you get what you want.&lt;br /&gt;&lt;br /&gt;This seems a lot like what the agile development philosophy says. We have a set of stories that define where we want to get to; during development we monitor progress with daily standups, regular integration, or more empirically with techniques like Scrum; and we change the stories, the solutions, the code, the team etc, etc, until we get where we want to be.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/02/drawing-parallels.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113987056962280261'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113987056962280261'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-113793746550963898</id><published>2006-01-22T13:40:00.000-08:00</published><updated>2006-02-12T15:59:05.476-08:00</updated><title type='text'>Java Generics Niggle</title><content type='html'>I've been using Java 5.0 in anger for a while now, and largely I like the extra type safety and (to some extent) expressiveness that the generic types provide, but there are some things that are somewhat annoying. I want to write a test with an assertion that checks the type of the object that I get out of an untyped map - the map is provided by a library class, and can hold different types of objects under different keys, so it can't be parameterised by type. I want to write an assertion something like this (using the JMock assertion syntax):&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;     assertThat(myMap.get(KEY_NAME), isA(List&amp;lt;String&amp;gt;.class));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The immediate problem is that this does not compile. &lt;code&gt;List&amp;lt;String&amp;gt;.class&lt;/code&gt; is not valid Java 5.0 syntax. Trying various possibilities, it seems the best I can do is &lt;code&gt;List.class&lt;/code&gt;. I also tried &lt;code&gt;new ArrayList&amp;lt;String&amp;gt;().getClass()&lt;/code&gt;, which compiles but is unsatisfactory because it is too specific about the class that implements the &lt;code&gt;List&lt;/code&gt;, and also, testing shows that the result of executing &lt;code&gt;new ArrayList&amp;lt;String&amp;gt;().getClass()&lt;/code&gt; is just &lt;code&gt;ArrayList&lt;/code&gt;, not &lt;code&gt;ArrayList&amp;lt;String&amp;gt;&lt;/code&gt; as we might hope and expect.&lt;br /&gt;&lt;br /&gt;What is going on here? The problem is that generics in Java are a compile time rather than a runtime artifact. When &lt;a href="http://bracha.org/"&gt;Gilad Bracha&lt;/a&gt; was deciding how to implement generics for Java, he decided to take an approach based on &lt;a href="http://pizzacompiler.sourceforge.net"&gt;Pizza&lt;/a&gt; and &lt;a href="http://homepages.inf.ed.ac.uk/wadler/gj/"&gt;GJ&lt;/a&gt; by &lt;a href="http://wadler.blogspot.com/"&gt;Phil Wadler&lt;/a&gt;. The compiler takes the parameterisation of types given in the source code, and through a process of &lt;em&gt;erasure&lt;/em&gt; uses them to insert the casts that would be needed if we were to write this code under Java 1.4. The effect of this is that in the bytecode, and therefore at runtime, there is no information about type parameters. Hence the problem I showed above, where we are trying to make assertions at runtime.&lt;br /&gt;&lt;br /&gt;When &lt;a href="http://research.microsoft.com/~dsyme/"&gt;Don Syme&lt;/a&gt; and &lt;a href="http://research.microsoft.com/~akenn/"&gt;Andrew Kennedy&lt;/a&gt; implemented &lt;a href="http://research.microsoft.com/~akenn/generics/DesignAndImplementationOfGenerics.pdf"&gt;generics for .NET&lt;/a&gt;, they took a different approach, updating the bytecode instructions in the CLR to allow the generic type information to be held and accessed at runtime. I haven't spent the time to find a neat and elegant way of performing the test that I want, but the &lt;a href="http://msdn2.microsoft.com/en-us/library/b8ytshk6.aspx"&gt;documentation&lt;/a&gt; gives the impression that it should be possible to create a suitable library method. But I want this in Java, maybe in &lt;a href="https://mustang.dev.java.net/"&gt;Mustang&lt;/a&gt;...</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/01/java-generics-niggle.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113793746550963898'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113793746550963898'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-113883009396205595</id><published>2006-02-01T21:40:00.000-08:00</published><updated>2006-02-01T13:41:34.020-08:00</updated><title type='text'>Spring AOP</title><content type='html'>I've generally been a bit sceptical about the applicability of aspect-oriented programming (AOP). There seemed to be a lot of hype coming out of places like IBM about AspectJ, but I could never see this really taking off, as it is really a different language, rather than an extension to Java. Kevin Sullivan (et al) have an &lt;a href="http://www.cs.iastate.edu/~hridesh/papers/p166-sullivan.pdf"&gt;interesting paper&lt;/a&gt; which balances some of the benefits and some of the problems, using AOP to design software. After reading this I was still thinking that aspects might not be that useful.&lt;br /&gt;&lt;br /&gt;However, I've recently been looking at the AOP support in Spring, which gives the programmer an API to use, rather than extra programming language constructs. Although this restricts what is possible to a certain degree, it does allow AOP to be used in "normal Java programs", especially as one of the tenets of Spring's design philosphy is to be non-invasive. I have managed to add two useful aspects to my current project, without changing the existing source code, but just by adding some new classes, and some configuration. Spring then weaves its magic to connect things up at runtime (using a lot of reflection and dynamic proxies behind the scenes). Regardless of this, I was pretty impressed.&lt;br /&gt;&lt;br /&gt;In the application I am working on at the moment, we are calling a number of external web services, and we have been somewhat concerned with the performance of these. We wanted to measure how long calls to the web services take to complete. By using an aspect, we can write the profiling code in one place, and apply it across all of our web service calls. By configuring it in the Spring application context, we can also insert or remove the profiling code without having to alter the Java source.&lt;br /&gt;&lt;br /&gt;I wrote the following simple class, which implements an interface from the Spring API, to implement some &lt;em&gt;around advice&lt;/em&gt;. There's a lot of terminology used in AOP, for a quick guided tour, see this &lt;a href="http://aosd.net/wiki/index.php?title=Glossary"&gt;glossary&lt;/a&gt;.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class SimpleProfilingAdvice implements MethodInterceptor {&lt;br /&gt;   &lt;br /&gt;    public Object invoke(MethodInvocation invocation) throws Throwable {&lt;br /&gt;               &lt;br /&gt;        StopWatch sw = new StopWatch();&lt;br /&gt;        sw.start(invocation.getMethod().getName());&lt;br /&gt;        Object returnValue = invocation.proceed();&lt;br /&gt;        sw.stop();&lt;br /&gt;       &lt;br /&gt;        report(invocation, sw.getTotalTimeMillis());&lt;br /&gt;        return returnValue;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private void report(MethodInvocation invocation, long ms) {&lt;br /&gt;        // print out the timing info etc&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then in the configuration, I just add:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;   &amp;lt;bean id="webServiceFacade" class="WebServiceFacadeImpl" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;bean id="profiler" class="SimpleProfilingAdvice"&gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;bean id="proxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&amp;gt;&lt;br /&gt;       &amp;lt;property name="beanNames"&amp;gt;&lt;br /&gt;            &amp;lt;list&gt;&amp;lt;value&gt;webServiceFacade&amp;lt;/value&gt;&amp;lt;/list&amp;gt;&lt;br /&gt;        &amp;lt;/property&gt;&lt;br /&gt;        &amp;lt;property name="interceptorNames"&amp;gt;&lt;br /&gt;            &amp;lt;list&amp;gt;&lt;br /&gt;                &amp;lt;value&gt;profiler&amp;lt;/value&amp;gt;&lt;br /&gt;            &amp;lt;/list&amp;gt;                     &lt;br /&gt;        &amp;lt;/property&amp;gt;&lt;br /&gt;    &amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Spring automatically creates a proxy for my webServiceFacade bean, which intercepts calls, and runs my advice instead (which in turn, proceeds to call the original method).&lt;br /&gt;&lt;br /&gt;In the same vein, I took the ideas presented by &lt;a href="http://tiling.org"&gt;Tom White&lt;/a&gt; in his article on &lt;a href="http://www.onjava.com/pub/a/onjava/2003/08/20/memoization.html"&gt;using memoization for caching&lt;/a&gt;, and created a caching aspect. I could then chain this together with my profiling aspect to compare performance of the calls with and without caching.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/02/spring-aop.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113883009396205595'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113883009396205595'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-113874118020350822</id><published>2006-01-31T21:00:00.000-08:00</published><updated>2006-02-01T13:02:00.636-08:00</updated><title type='text'>More on Generics</title><content type='html'>In a recent discussion on the &lt;a href="http://slurp.doc.ic.ac.uk"&gt;Slurp&lt;/a&gt; list, Sun's pages on &lt;a href="http://java.sun.com/docs/books/tutorial/extra/generics/morefun.html"&gt;advanced use of generics&lt;/a&gt; came under some scrutiny. &lt;br /&gt;&lt;br /&gt;Sun says:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;Suppose we want to create a TreeSet&amp;lt;String&amp;gt; and pass in a suitable comparator, We need to pass it a Comparator that can compare Strings. This can be done by a Comparator&amp;lt;String&amp;gt;, but a Comparator&amp;lt;Object&amp;gt; will do just as well.&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Slurp say:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;We think introducing Object into a discussion about generics is bad... It would be better if the page had avoided Strings and Objects, and said:&lt;br /&gt;&lt;br /&gt;&amp;quot;Suppose we want to create a TreeSet&amp;lt;Chicken&amp;gt; and pass in a suitable comparator. We need to pass it a Comparator that can compare Chickens. This can be done by a Comparator&amp;lt;Chicken&amp;gt;, but a Comparator&amp;lt;Animal&gt; (where Animal is a superclass of Chicken) will do just as well. We COULD write the constructor as TreeSet(Comparator&amp;lt;? extends Animal&amp;gt; c)  but it would be better to avoid mentioning a specific superclass of Chicken. Therefore TreeSet(Comparator&amp;lt;? super Chicken&amp;gt; c)  is best.&amp;quot;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;code&gt;Comparator&amp;lt;? extends Animal&amp;gt;&lt;/code&gt; is not quite good enough, as I can pass in a &lt;code&gt;FreeRangeChickenComparator()&lt;/code&gt; which ranks chickens based on their happiness, an attribute not exposed in the Chicken superclass, but this is not really the point here. I agree that what Sun's page says is confusing. In most cases, a &lt;code&gt;Comparator&amp;lt;Object&amp;gt;&lt;/code&gt; will not do &amp;quot;just as well&amp;quot;, as it will likely return a different ordering.&lt;br /&gt;&lt;br /&gt;If you're just using the TreeSet as an efficient storage structure then any order will indeed do, but if you want to iterate over the contents, then you likely want a particular total ordering, e.g. alphabetically by species, or average egg diameter...&lt;br /&gt;&lt;br /&gt;TreeSets in general are slightly annoying, as they try to combine being a &lt;code&gt;TreeSet&amp;lt;E extends Comparable&amp;gt;&lt;/code&gt;, with being a &lt;code&gt;TreeSet&amp;lt;E&amp;gt;&lt;/code&gt; with a constructor taking a &lt;code&gt;Comparator&amp;lt;? super E&amp;gt;&lt;/code&gt; (as we have seen). In order to support passing in a custom Comparator (which could work on any type), the set must be declared as &lt;code&gt;TreeSet&amp;lt;E&amp;gt;&lt;/code&gt;, rather than &lt;code&gt;TreeSet&amp;lt;E extends Comparable&amp;gt;&lt;/code&gt;.&lt;br /&gt; &lt;br /&gt;This leads to a few loopholes. I can easily create a &lt;code&gt;TreeSet&amp;lt;NotComparable&amp;gt;&lt;/code&gt;, where upon calling &lt;code&gt;treeSet.add(new NotComparable());&lt;/code&gt; (more than once, as you don't need to compare anything when you add the first element) causes a runtime &lt;code&gt;ClassCastException&lt;/code&gt;. So this test compiles and passes:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public void testGenericTreeSet() {&lt;br /&gt;     &lt;br /&gt;    try {&lt;br /&gt;        Set&amp;lt;NotComparable&amp;gt; ts = new TreeSet&amp;lt;NotComparable&amp;gt;();&lt;br /&gt;        ts.add(new NotComparable());&lt;br /&gt;        ts.add(new NotComparable());&lt;br /&gt;     fail();&lt;br /&gt;     } catch(Throwable t) {&lt;br /&gt;         assertThat(t, isA(ClassCastException.class));&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Generics are not being very helpful here, you'd hope that all this extra "type-safety" would allow this sort of thing to be flagged up at compile time, but making this class work in two ways, and in keeping everything backwardly compatible, there are some cracks between the floorboards.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/01/more-on-generics.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113874118020350822'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113874118020350822'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-113770870811727806</id><published>2006-01-19T23:11:00.000-08:00</published><updated>2006-01-23T13:14:51.243-08:00</updated><title type='text'>Testing Controllers With Mocks</title><content type='html'>One of the reasons for setting up this page was I wanted to write something somewhere about the new testing techniques I've been using over the past few days. I'm working on a Java web application, using a fairly standard &lt;a href="http://c2.com/cgi/wiki?ModelViewController"&gt;MVC&lt;/a&gt; structure. Working on an XP team, I've always felt a little uneasy about not having a good way to build controllers test first. Typically in past projects I've tested controllers indirectly by using tools like HttpUnit to interact with the web front end, and exercise the view and controller components together. This approach has a number of drawbacks. In the case of a failure, it is difficult to determine whether the bug is in the view or the controller (or even the model). It is also necessary to develop the view and the controller in tandem, as one cannot be tested without the other.&lt;br /&gt;&lt;br /&gt;On my current project, we are using &lt;a href="http://www.springframework.org"&gt;Spring&lt;/a&gt; to provide the MVC framework. This allows us to make use of some of the other facilities provided by Spring to enhance our testing.&lt;br /&gt;&lt;br /&gt;Spring provides support for unit testing controllers independently. This has a number of advantages:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;We can develop controllers test-first.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Breakages in the unit tests point explicitly to problems in the controller, rather than problems in one of the combination of Model, View and Controller.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;We can run the unit test outside of the container, meaning that we do not have to deploy within each code/test cycle.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The tests themselves run faster.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;We can develop and test all of our controller code before developing any of the view components.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;We can develop and test all of our controller code before creating the Spring application-context.xml, which makes the requirements for the contents of this file much clearer.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;The difficulty we had had with unit testing controllers previously was that the methods in their public interface tended to take an &lt;code&gt;HttpServletRequest&lt;/code&gt; and &lt;code&gt;HttpServletResponse&lt;/code&gt; as parameters, and operate on these. When running a unit test, such objects are not normally to hand, and are difficult to construct. Spring aids this situation by providing the classes &lt;code&gt;MockHttpServletRequest&lt;/code&gt; and &lt;code&gt;MockHttpServletResponse&lt;/code&gt; in spring-mock.jar (note that these classes are not part of the core Spring jar). Here is an example of how we can use them in a JUnit test case.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import org.springframework.mock.web.MockHttpServletRequest;&lt;br /&gt;import org.springframework.mock.web.MockHttpServletResponse;&lt;br /&gt;import org.springframework.web.servlet.ModelAndView;&lt;br /&gt;&lt;br /&gt;public MyControllerTest extends TestCase {&lt;br /&gt;&lt;br /&gt;    public void testGettingIndexPage() throws Exception {&lt;br /&gt;&lt;br /&gt;        MyController controller = new MyController();&lt;br /&gt;        controller.setIndexView("index.jsp");&lt;br /&gt;&lt;br /&gt;        MockHttpServletRequest request = new MockHttpServletRequest();&lt;br /&gt;        MockHttpServletResponse response = new MockHttpServletRequest();&lt;br /&gt;&lt;br /&gt;        request.setMethod("GET");&lt;br /&gt;&lt;br /&gt;        ModelAndView modelAndView = controller.handleRequest(request, response);&lt;br /&gt;&lt;br /&gt;        assertEquals("Should get index page", modelAndView.getViewName(), "index.jsp");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;This test shows that we intend our controller to respond to requests on the base url to display &lt;code&gt;index.jsp&lt;/code&gt;. By writing the test first, we can see what we need to implement in our controller. To make this test pass requires only a very simple controller (which will be a subclass of one of the Spring MVC controllers).&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import org.springframework.web.servlet.mvc.AbstractController;&lt;br /&gt;&lt;br /&gt;public class MyController extends AbstractController {&lt;br /&gt;&lt;br /&gt;    private String indexView;&lt;br /&gt;&lt;br /&gt;    public void setIndexView(String viewName) { indexView = viewName; }&lt;br /&gt;    public String getIndexView() { return indexView; }&lt;br /&gt;&lt;br /&gt;    public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;        return new ModelAndView(getIndexView());&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To make things a bit more interesting, we can add a test that passes in some parameters on the request, and expects an appropriate response, for example passing in a search query and expecting a results page back. Adding to our test case, we can write:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;    public void testSearching() throws Exception {&lt;br /&gt;&lt;br /&gt;        MyController controller = new MyController();&lt;br /&gt;        controller.setSearchResultsView("results.jsp");&lt;br /&gt;        MockHttpServletRequest request = new MockHttpServletRequest();&lt;br /&gt;        MockHttpServletResponse response = new MockHttpServletResponse();&lt;br /&gt;        request.setMethod("GET");&lt;br /&gt;&lt;br /&gt;        request.addParameter("query","testing");&lt;br /&gt;&lt;br /&gt;        ModelAndView modelAndView = controller.handleRequest(request, response);&lt;br /&gt;&lt;br /&gt;        assertEquals("Should get results page", modelAndView.getViewName(), "results.jsp");        &lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Again the intention of the test is pretty clear (we can now see that our testcase might benefit from factoring some common setup into a setup method, but we'll leave that for now), and again, we don't need to add much to our controller to make it pass.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class MyController extends AbstractController {&lt;br /&gt;&lt;br /&gt;    //  in addition to the fields and accessors from before...&lt;br /&gt;    private String searchResultsView;&lt;br /&gt;&lt;br /&gt;    public void setResultsView(String viewName) { searchResultsView = viewName; }&lt;br /&gt;    public String getSearchResultsView() { return searchResultsView; }&lt;br /&gt;&lt;br /&gt;    public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;&lt;br /&gt;        String query = request.getParameter("query");&lt;br /&gt;        if ( query != null ) {&lt;br /&gt;            // perform the search&lt;br /&gt;            return new ModelAndView(getSearchResultsView());&lt;br /&gt;        } else {&lt;br /&gt;            return new ModelAndView(getIndexView());&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This shows a couple of very simple iterations of writing tests and implementation for a controller, you can go a lot further, making both the tests and the implementation more sophisticated. The main point is that we have built and tested the controller in a way that allows quick iteration, promotes clarity and good test coverage, and does not require a view component to be written to do so.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/01/testing-controllers-with-mocks.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113770870811727806'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113770870811727806'></link><author><name>Robert Chatley</name></author></entry><entry><id>tag:blogger.com,1999:blog-21220738.post-113778111837120171</id><published>2006-01-20T21:36:00.000-08:00</published><updated>2006-01-21T04:30:37.756-08:00</updated><title type='text'>More Mockery</title><content type='html'>In my last post I described using Spring's mock request and response classes to unit test controllers. The examples given were very simple. In real situations, controllers typically depend on other resources, often to provide data sources etc. These can also be troublesome to test with, and cause tests to be unpredictable and slow.&lt;br /&gt;&lt;br /&gt;To combat this, and create fast, decoupled unit tests, I have been using &lt;a href="http://www.jmock.org"&gt;JMock&lt;/a&gt; in tandem with the Spring mock library. This allows very expressive tests to be created, which run independently of any actual data source dependencies, and have predicatable results.&lt;br /&gt;&lt;br /&gt;For example, say we are writing a controller to list the avaiable books in a library. We may have a &lt;code&gt;Library&lt;/code&gt; interface, which we call to query an underlying database. Using JMock we can write a test like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class LibraryControllerTest extends MockObjectTestCase {&lt;br /&gt;    &lt;br /&gt;    private static final String MODEL_NAME = "books";&lt;br /&gt;    private static final String INDEX_PAGE = "index.jsp";&lt;br /&gt;&lt;br /&gt;    private Mock mockLibrary;&lt;br /&gt;    private LibraryController controller;&lt;br /&gt;    private MockHttpServletRequest request;&lt;br /&gt;    private MockHttpServletResponse response;&lt;br /&gt;&lt;br /&gt;    protected void setUp() throws Exception {&lt;br /&gt;        super.setUp();&lt;br /&gt;        mockLibrary = mock(Library.class);&lt;br /&gt;        &lt;br /&gt;        request = new MockHttpServletRequest();&lt;br /&gt;        response = new MockHttpServletResponse();&lt;br /&gt;        request.setMethod("GET");&lt;br /&gt;        &lt;br /&gt;        controller = new LibraryController();&lt;br /&gt;        controller.setLibrary((Library)mockLibrary.proxy());&lt;br /&gt;        controller.setIndexView(INDEX_PAGE);&lt;br /&gt;        controller.setModelName(MODEL_NAME);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void testListingBooks() throws Exception {&lt;br /&gt;        mockLibrary.expects(once()).method("getAvailableBooks").will(returnValue(new BookList()));&lt;br /&gt;        ModelAndView modelAndView = controller.handleRequest(request, response);&lt;br /&gt;        assertThat(modelAndView.getViewName(),eq(INDEX_PAGE));&lt;br /&gt;        assertThat(modelAndView.getModel().get(MODEL_NAME), isA(BookList.class));&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here I have set up a mock of the &lt;code&gt;Library&lt;/code&gt; interface, and in &lt;code&gt;testListingBooks&lt;/code&gt; set up an expectation that this mock will have its &lt;code&gt;getAvailableBooks()&lt;/code&gt; method called once durnig the course of the test. I have also set a stub return value, so that when this happens, the mock will return a new &lt;code&gt;BookList&lt;/code&gt;, so that the returned value is predictable. See the &lt;a href="http://www.jmock.org/docs.html"&gt;JMock documentation&lt;/a&gt; for more on setting up mocks with expectations.&lt;br /&gt;&lt;br /&gt;Now we have a concise test that expresses what we want our controller to do. When we request the page, we expect it to call the Library, and put that information into the &lt;code&gt;ModelAndView&lt;/code&gt; that is returned from &lt;code&gt;handleRequestInternal()&lt;/code&gt;. &lt;br /&gt;To make this test pass, again requires only a simple controller.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import org.springframework.web.servlet.mvc.AbstractController;&lt;br /&gt;&lt;br /&gt;public class LibraryController extends AbstractController {&lt;br /&gt;&lt;br /&gt;    private String indexView;&lt;br /&gt;    private String modelName;&lt;br /&gt;    private Library library;&lt;br /&gt;&lt;br /&gt;    public void setIndexView(String viewName) { indexView = viewName; }&lt;br /&gt;    public String getIndexView() { return indexView; }&lt;br /&gt;    public void setModelName(String name) { modelName = name; }&lt;br /&gt;    public String getModelName() { return modelName; }&lt;br /&gt;    public void setLibrary(Library lib) { library = lib; }&lt;br /&gt;    public Library getLibrary() { return library; }&lt;br /&gt;&lt;br /&gt;    public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;        BookList list = library.getAvailableBooks();&lt;br /&gt;        return new ModelAndView(getIndexView(),getModelName(),list);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Another nice thing that we can do, is to test the case where there is a problem with the data source. We can set up an expectation on the mock &lt;code&gt;Library&lt;/code&gt; that it will throw an exception when it is called, and then check that the controller gives an appropriate response, for example routing to an error page.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class LibraryControllerTest extends MockObjectTestCase {&lt;br /&gt;&lt;br /&gt;    private static final String ERROR_PAGE = "error.jsp";&lt;br /&gt;    ...&lt;br /&gt;    public void testErrorFromDataSource() throws Exception {&lt;br /&gt;      controller.setErrorPage(ERROR_PAGE);  mockLibrary.expects(once()).method("getAvailableBooks").will(throwException(new DatabaseDownException()));&lt;br /&gt;        ModelAndView modelAndView = controller.handleRequest(request, response);&lt;br /&gt;        assertThat(modelAndView.getViewName(), eq(ERROR_PAGE));&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This sets up the mock Library to throw an exception when it is called, and checks that the view that we get back is the error page we expect. We can then complete the controller.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class LibraryController extends AbstractController {&lt;br /&gt;    ...&lt;br /&gt;    // field, and getter and setter for errorPage here&lt;br /&gt;    ...&lt;br /&gt;    public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;        try {&lt;br /&gt;            BookList list = library.getAvailableBooks();&lt;br /&gt;            return new ModelAndView(getIndexView(),getModelName(),list);&lt;br /&gt;        } catch (DatabaseDownException dde) {&lt;br /&gt;            return new ModelAndView(getErrorPage());&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Again, writing the test first gives us a clear direction for what we want to do when we write the code, and we can be sure that the controller is behaving correctly when our tests pass, without having to construct any of the view components.</content><link rel='alternate' type='text/html' href='http://chatley.com/blog/2006/01/more-mockery.html'></link><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113778111837120171'></link><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21220738/posts/default/113778111837120171'></link><author><name>Robert Chatley</name></author></entry></feed>