Elements of Testing Style
It's been way too long since I blathered on about style issues. Today I'd like to talk about testing style. This article assumes you are already writing tests and already using something approaching a Test-Driven Development process -- I'm not here to argue about process, at least not today.
Today the topic is the actual construction of individual tests, how to name them, how to group them, where to get data from and the like.
I suspect I'll think of five more things right after I post this, so look for an update sometime in the future. The update will also address all the places where everybody tells me that I'm totally wrong.
Topics: Ruby on Rails
Upcoming Pathfinder Appearances
Here are a couple of upcoming Ruby and Rails-based appearances by Pathfinder personnel:
On Tuesday, June 23, Noel Rappin (referring to himself in the third person) will be the guest speaker at the Chicago Ruby.org monthly meeting. The meeting starts at 6:00 at Chicago Ruby's downtown loop meeting location, see the link for details. The working title of my talk is "I'd Like To Start Testing. Now What?" and it'll be an informal discussion of testing tools and good practice.
The schedule for WindyCityRails was announced this week. The conference is September 12, 2009 at the Westin Chicago River North. John McCaffrey from Pathfinder will be presenting "Super-easy PDF Generation with Prawn and Prawnto", and I'll be up there with "How To Test Absolutely Anything".
Other speakers include Ryan Singer from 37signals, Ben Scofield from Viget Labs, and Yehuda Katz from Engine Yard.
Registration through August 1st is $99, there are a couple of tutorial sessions also available for purchase.
This was a very well-run regional conference last year, and I'm excited for this year's edition. Hope to see you there.
Topics: Ruby on Rails
How to learn a new programming language or framework
While never untrue, it is more of a necessity now, that a programmer should know more than just one language or framework. After being a focussed Java/J2EE developer for a long time since college, in the last couple of years, I plunged into .NET, Ruby/Rails and then Javascript/prototype/jQuery etc and now onto groovy/grails. With name like Erlang, Scala, Compass, git, blueprint, flex flying around us everywhere, it can be overwhelming and we need a plan to pick, peruse, acquire them. Here is a list of things I do when learning a new skill.
Topics: Grails, Groovy, Java, ruby, Ruby on Rails
The Return of the Cucumber
I mentioned last week that the RubyMine post was replacing what I had meant to write about. Well, this week we finally get to it...
It's been about ten weeks since I wrote about Cucumber the first time and the second time. Since then, I've continued to use Cucumber and now seemed like a good time to update some thoughts on how and why it seems to be working for us.
The big headline, of course, is that I'm still using it after ten weeks. I'm pretty quick to abandon tools that aren't pulling their weight, so just the fact that Cucumber is still in the toolbox means that despite the time that it takes to write Cucumber tests and step definitions, I'm finding the process of writing the tests and the tests themselves to be valuable.
Topics: cucumber, Ruby on Rails, Testing
Back To The Ruby Mines
This actually wasn't the post I was planning to write this week, but a couple of days ago I got it in my head to try the latest version of RubyMine, the Ruby and Rails IDE from JetBrains.
Now, I tried this with the beta version back in December, and thought it had a long way to go. However, there's been a lot of online chatter about it over the last few months. (Gregg Pollack was particularly enthusiastic in his RailsConf talk), and I thought I'd go back and try again. And I started Twittering about it again, and got some responses, so I thought I'd do a longer write up.
The executive summary is that I started using this on Wednesday and haven't stopped yet. It's come a very long way, and although there are still annoyances, it felt better to me than the other Ruby IDE's. I think it's not quite as solid as my normal TextMate/termial prompt combination, but it's improving rapidly. Overall, this is the first time that JetBrains' Ruby IDE gave me that pleasant "this is like IntelliJ" feeling.
One thing I definitely learned from my years as a happy IntelliJ user back when I wrote more Java code, is that JetBrains releases often, their betas are usually very solid, and they add new stuff really, really rapidly. So my expectations are high that RubyMine will continue to improve. Continue reading »
Topics: Ruby on Rails
Stick with ERB or move to Haml
Haml is gaining popularity in Rails community. It claims higher productivity compared to defacto ERB templating. Not everybody agrees though. I see 2 short-term problem with haml.
- ERB is similar to it pre-decessor and hence easier to learn. Compared to JSP etc. ERB is similar, you still see lots of HTML tag with interleaved ruby (or Java). Although verbose, it is closer to how your HTML would finally look like.
- If your team has a dedicated HTML programmer (Designer as we may call them). These folks are very good at plain HTML and don't want the trouble of converting files and having all the plumbing around when working. It is not efficient for them.
Despite this, I see Haml as valid alternative for following reasons:
Topics: erb, haml, ruby, Ruby on Rails
Comparing Ruby Mock Object Libraries
Continuing on the theme of comparing similar things that I started last week, this week I'll be taking on Mock Object libraries.
The purpose of a mock object library is to allow you to create "fake" objects that can take the place of the regular objects in your application during testing (you'll sometimes see them called "test doubles", by analogy with a stunt double, another kind of stand-in).
There are a several reasons why you might want to use a test double in your tests, the two most common are probably these:
- To take the place of a hard to create or expensive to access object or method call, such as a web services call. Using the test double lets the test system pretend that the expensive object is there, but at a much lower time cost.
- To isolate an object being tested from the details of the rest of the system. In Rails, for example, a controller test might create test doubles for methods in the model so that the controller test can pass or fail separately from whether the model implementation is correct.
Ruby's open object model and duck-typing makes creating test double objects relatively easy compared to stricter languages like Java. There are four major mock objects packages in Ruby:
- FlexMock is the original Ruby mock object package
- Mocha is quasi-official in that the Rails team uses it for their tests.
- RSpec defines its own mock package
- RRis the newest entry, with shorter syntax and a couple of new features
Here's a tour of what each package looks like, and when you might use each feature.
Topics: Ruby on Rails
Factory tools for fixture replacement: a comparison
Continuing on the general theme of blog posts that people actually asked me to do... this week, I'll be taking a comparative look at fixture replacement tools. The general request was to have one place that compared the features of the various libraries so that a prospective fixture replacer might make a more informed choice.
So here goes, I'll try to keep the editorializing to a minimum, but no promises.
Fixture replacement or factory tools replace the global nature of Rails fixture data with the ability to easily create new objects based on sample valid data previously defined by the developer. Factory tools have several advantages, including keeping each test independent of other tests, since you are no longer using global fixtures, and allowing the important data for each test to be defined in that test.
Updated to correct some errors caught in the first few comments.
Self-promotion alert: A full description of why to use fixture replacements and an in-depth look at one of these tools is available in the full version of Rails Test Prescriptions available wherever fine PDF books are sold as long as you think the only place fine PDF books are sold is http://www.railsrx.com.
Continue reading »
Topics: Ruby on Rails
Catching Ajax Errors with Prototype and Rails
In an exclusively Ajax application it can be difficult for a user to determine when their connection to the server has dropped. For example, we at Pathfinder use an excellent internal tool to keep track of our time, and the primary screen in it provides a lot of Ajax-y fields. But if, say, I disconnect my laptop, plug in at home, and forget to connect to our VPN, I can waste quite a lot of time and energy putting in information without realizing it isn't being sent to the server at all.
To fix this problem is a little less obvious than it might seem at first glance.
Topics: Ajax, Prototype, Ruby on Rails
Rails Testing Frequently Asked Questions — The Non-Code Version
Between my sessions at RailsConf, and the book promotion at Ruby Learning I've been fielding a lot of questions about Test-Driven Development and Rails. Here are five of the most common general questions.
Self promotional note: many of these questions and more are covered in detail in Rails Test Prescriptions, only $9 dollars for a book that covers all kinds of testing topics...
Continue reading »
Topics: Ruby on Rails
RailsConf ‘09: After the RailsConfening
A rambling set of notes and things while it's still in my head.
Topics: Ruby on Rails
Pathfinder Launches Beer Hunter, A New Flex + Ruby RIA
We just launched a new rich internet application for Destinationbeer.com, called Beer Hunter. It was written in Flex and Ruby on Rails and features mapping and 150 beers from around the world. We think it's pretty cool, so check it out, and let us know what you think. One of the things I really like about it is that the design pattern can be applied anywhere you're filtering products geographically and on attributes. Coffee? Wine? Jewelry? Chocolate? Travel Books? I particularly like the way the beer list visually sorts when you change a filter and the zoom interactions on the map.
There's more information in the case study on the Pathfinder web site, Sasha has written a related post on RubyAMF and Flex from the Flex perspective , and Justin has written one on Rails, AMF and Flex from the Rails perspective.
Topics: beer, Flex, mapping, rich internet applicaiton, Ruby on Rails
Process, Environment, and Incentives
I was having a conversation with a co-worker this week about the automated build server on a particular project. My co-worker had set up the server to fail the build if test coverage dropped below 100%, and I was less than convinced that this was a good idea.
We didn't debate it much, I wasn't doing a very good job of making my points, and we both had other things to do, but it got me thinking about process, community, and incentives. So I thought I'd ramble on about that for a while.
Thinking about it, I decided that having the build fail on a coverage drop, although I still think it's overkill, is not nearly as important as what happens after the build fails. Is it allowed to stay failed? Does the responsible developer fix it sheepishly? Is the responsible developer forced to wear a silly hat? What incentive is there for the developer to ensure the build status before checkin? Continue reading »
Topics: Ruby on Rails
RailsConf 2009: The RailsConfening
In just over a week, I'll be headed off to RailsConf for my second visit.
Here's an overview of some of the sessions I'm looking forward to.
First, of course, is my own: Below and Beneath TDD: Test-Last Development and Other Real-World Test Patterns. It's at 2:50 on Tuesday, May 5, in Ballroom B. I'll be talking about how Test-Driven Development can fail, how to recognize failure patterns, and how and why to move back to a successful process. No matter what your level of comfort is with testing, I think you'll get something out of this talk. It's going to be fun, and I'm excited about the chance to present.
I'm also going to be giving out free copies of Rails Test Prescriptions (well, it's an ebook, I'll be giving out free licenses). I haven't quite worked out the exact details yet, but it'll be similar to last year's plan, and will involve seeing me or attending my session. Follow the book on Twitter for information about giveaways. Follow me on Twitter for general updates about the conference.
And come up and say hi -- I'd love to meet people who read this blog or the Rails Prescriptions book.
Other talks and sessions that I'm particularly interested in include:
Topics: Ruby on Rails
Nested Contexts and Test Structure
I first started using Shoulda for my Rails tests, it took me a while to really understand how Shoulda wants me to use contexts.
In a traditional SUnit/JUnit test structure, the test setup gets the data in order, the actual test method does something and then tests assertions about the outcome
Continue reading »
Topics: Ruby on Rails
About Pathfinder
Follow the Blog
-
Get a monthly update on best practices for delivering successful software.
Subscribe via email
Subscribe via RSS
Categories
Topics
Archives
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
Blogroll
Recent
- Elements of Testing Style
- Aesthetics and Web Design
- Asterisk-Java Testing with Groovy
- 3 Misuses of Code Comments
- Fluently NHibernate
- Digging a Hole and Covering it with Leaves — The Software Development Version
- The Importance of User Experience - Do You Understand It in Your Bones?
- Writing Your Own Protocol With NSURLProtocol
- What’s In Your Dock: iPhone edition
- Feature Fatigue











