Unit Testing Without Frameworks

Discussion in 'Ruby' started by Sean O'Dell, Jul 6, 2004.

  1. Sean O'Dell

    Sean O'Dell Guest

    On Tuesday 06 July 2004 13:55, Lothar Scholz wrote:
    >
    > And to be honest i stopped unit tests, because the current libraries
    > GUI, networking, filesystems do not support them well enough. Hope
    > that this will improve in the future.


    I felt the same way. I got back into unit testing in a way I don't think most
    people would understand. I dropped frameworks altogether. I started just
    running anything found in a "tests" sub-directory of whatever project I was
    working on.

    Actually, I do have a framework of a sort: a single ruby file I use to launch
    tests that match a given name pattern. Here's the entire "framework":

    #!/usr/bin/ruby

    pattern = nil
    pattern = Regexp.new(ARGV.shift) if (ARGV.length > 0)

    Dir["tests/*"].each do | filename |
    next if (filename =~ /^\./)

    test = filename.clone
    test.slice!(/^.+\//)
    test.slice!(/\.rb$/)

    next if (not test =~ /^test_/)
    test.slice!(/^test_/)

    next if (pattern and not test =~ Regexp.new("^#{pattern}$"))

    print("---------- #{test}' ----------\n")
    system(filename)
    end

    print("---------- DONE ----------\n")



    Generally, in my tests, I just do whatever and let exceptions happen where
    they happen, and every test usually ends with a statement like:

    p a == expected_value

    So my entire "report" consists of a series of true or falses. When a false
    occurs, I just track it down and fix whatever caused the bug.

    Perhaps it's just my need for simplicity that makes this work better for me
    than a framework. Or perhaps current frameworks don't have the ability to
    really anticipate what everyone needs or wants. Whatever the reason, I am
    really into unit testing now.

    Sean O'Dell
    Sean O'Dell, Jul 6, 2004
    #1
    1. Advertising

  2. Sean O'Dell wrote:
    > On Tuesday 06 July 2004 13:55, Lothar Scholz wrote:
    >
    >>And to be honest i stopped unit tests, because the current libraries
    >>GUI, networking, filesystems do not support them well enough. Hope
    >>that this will improve in the future.

    >
    >
    > I felt the same way. I got back into unit testing in a way I don't think most
    > people would understand. I dropped frameworks altogether. I started just
    > running anything found in a "tests" sub-directory of whatever project I was
    > working on.
    >
    > Actually, I do have a framework of a sort: a single ruby file I use to launch
    > tests that match a given name pattern. Here's the entire "framework":
    >
    > #!/usr/bin/ruby
    >
    > pattern = nil
    > pattern = Regexp.new(ARGV.shift) if (ARGV.length > 0)
    >
    > Dir["tests/*"].each do | filename |
    > next if (filename =~ /^\./)
    >
    > test = filename.clone
    > test.slice!(/^.+\//)
    > test.slice!(/\.rb$/)
    >
    > next if (not test =~ /^test_/)
    > test.slice!(/^test_/)
    >
    > next if (pattern and not test =~ Regexp.new("^#{pattern}$"))
    >
    > print("---------- #{test}' ----------\n")
    > system(filename)
    > end
    >
    > print("---------- DONE ----------\n")
    >
    >
    >
    > Generally, in my tests, I just do whatever and let exceptions happen where
    > they happen, and every test usually ends with a statement like:
    >
    > p a == expected_value
    >
    > So my entire "report" consists of a series of true or falses. When a false
    > occurs, I just track it down and fix whatever caused the bug.
    >
    > Perhaps it's just my need for simplicity that makes this work better for me
    > than a framework. Or perhaps current frameworks don't have the ability to
    > really anticipate what everyone needs or wants. Whatever the reason, I am
    > really into unit testing now.
    >
    > Sean O'Dell
    >
    >


    I used to feel the same until I came across this page. It's the best 10
    minutes I've ever invested on the topic of unit testing.

    http://www.rubygarden.org/ruby?UsingTestUnit

    I evaluated but did not use unit-testing frameworks in Java and C++
    because they seemed like too much hassle.

    The above page describes a scenario using Test::Unit that is so simple,
    I bet it's even easier than many homegrown testing methods.
    Randy Lawrence, Jul 11, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phillip Lord

    Unit testing GUI, possible frameworks

    Phillip Lord, Mar 2, 2004, in forum: Java
    Replies:
    0
    Views:
    319
    Phillip Lord
    Mar 2, 2004
  2. Replies:
    7
    Views:
    314
    Alexander Draeger
    Mar 29, 2009
  3. John Maclean
    Replies:
    1
    Views:
    329
    Martin P. Hellwig
    Apr 13, 2010
  4. Ulrich Eckhardt

    unit-profiling, similar to unit-testing

    Ulrich Eckhardt, Nov 16, 2011, in forum: Python
    Replies:
    6
    Views:
    315
    Roy Smith
    Nov 18, 2011
  5. Bill Mosteller
    Replies:
    0
    Views:
    209
    Bill Mosteller
    Oct 22, 2009
Loading...

Share This Page