The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Declarative Tests

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Declarative Tests Posted: Nov 22, 2009 8:27 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Declarative Tests
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
As a result of the current RoR gig I've become addicted to the declarative syntax for test-unit:
  class TC_Foo < Test::Unit::TestCase
    test "foo should return the string 'hello'" do
      assert_equal('hello', @obj.foo)
    end

    # vs.

    def test_foo_should_return_hello
      assert_equal('hello', @obj.foo)
    end
  end

When you first look at that you'll probably think it's just a silly cosmetic change. But, after using for a while I have to admit that it's had two effects on my testing, both positive.

First, and foremost, I now write more descriptive test descriptions. With the old "def test_something" I found that I tended to be overly terse. With the declarative syntax I tend to be more descriptive. That's a good thing, because it's easier for me (or someone else) to look at that test later and more easily determine just what the purpose of that test is.

Second, I tend to break out groups of assertions that I had previously lumped together into separate tests. This is a function of the first change, i.e. by writing more descriptive tests I limit the assertions to those that actually match my description. So, if an assertion is actually testing something *slightly* different, I feel more comfortable (for lack of a better word) writing it out into a separate test because I'm writing a more verbose description.

I'm not necessarily down to one assertion per test (as some people advocate), but my average number of assertions per test definitely dropped. :)

BTW, the declarative syntax has been added to test-unit 2 and will be part of the 2.0.6 release!

Read: Declarative Tests

Topic: Setup Ruby Enterprise Edition, nginx and Passenger (aka mod_rails) on Ubuntu Previous Topic   Next Topic Topic: Time zone warp

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use