Unit Testing Without Frameworks

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

···

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.

Sean O'Dell 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.

···

On Tuesday 06 July 2004 13:55, Lothar Scholz wrote: