Lazytest 0.1.0

Benny is happy to announce his second published piece of software:
“lazytest” available as gem. You may wonder what happened to my first
“FaceToFace”. There will be an update in the near future…

Dear list,

I hope this is useful for someone and I am curious what you think about

The code itself is no big deal and always open for improvements (as my
english is).

== Overview

lazytest allows you to do quick and easy testing and benchmarking of
library while developing it

I found the available solutions for unit tests too laborious and wanted
be able to the testing directly where I program and independantly from a
certain directory strucure.

I also wanted to be able to test alternativ implementations and
them to be able to get the best and fastest solution.

So the idea came up to create a something that could be included to do
tests but that only would run the tests when the file is called from the
shell. If it is included no test should be run.

The second idea was to have the tests been written in the DATA area of
file (everything after ‘END’ ) in YAML format to be easy and

== Example of Usage

To use it your file should look like this:

require ‘rubygems’
require_gem ‘lazytest’

Here: stuff that is not needed for the test


Here: definitions of the classes that should be tested



You might also pass a block to prepare_tests() that will only be
when running a test.

The Classes you define between the calls of prepare_tests and
run_tests will be automagically detected.

=== Setting up the tests
After ‘END’ you write your tests in YAML style. It is a YAML hash
the key is the class name with the initialization code (here: and the value is a hash of methods (e.g. empty?) and their
expected results (e.g. %s == true).

empty?: %s == true
class: == “Array”
dipsy: %s == NoMethodError
- %s == 4
- %s != 0
- %s > 3

Please note that YAML identation is two spaces for each level!

When running the tests the methods is applied on the created object and
result is placed inside the expected result where you placed the ‘%s’.
expected result is ruby code that should evaluate to ‘true’.

Tests that return false/nil are assumed to be failed.

That’s all! Simple, isn’t it?

You can even omit the ‘.new()’ if your Class doesnt need parameters for

If you want to disable a test, simply place a ‘#’ at the beginning of

=== Running the tests
Simply call the file from the shell, either like this:

./my_lib.rb test

or if it is not executable:

ruby my_lib.rb test

You will get a summary of the test results and more verbose information
about failed tests and errors.

If you pass the option ‘-v’ you will also see the verbose information
the tests that passed.

To get help:

./my_lib.rb help test

== Benchmarking
Simply pass the option ‘-b NUMBER’ when you call the script, where
how many iterations you want to run on your tests for the benchmark.
that only passed tests will be used for benchmarking.

== Other options
You may want to suppress the output of the test results when running
This can be achieved by using the option ‘-n’.

Maybe you want to reuse the output of the results for some further
processing. Therefor you might use the option ‘-y’ which returns the
results as hash in YAML style.

== Special: Testing and benchmarking alternativ Implementations
Sometimes you have different options how to implement things.

To evaluate this options, simply setup the alternative classes as
of your main implementation class and overwrite the methods that you
to differ.

Please make sure that their names contain the word ‘TestCase’ somewhere.

Thats it!

You might simply test and benchmark them in addition to the main
implementation by using the option ‘-a’ when calling the script.

So you can easily check, if they contain hidden errors and what
implementation is the fastest.

I leave them in the script even after rearranging the main
implementation to
the best, simply to be able to see what I already tried when I feel the
need to optimize later again.
They don’t hurd me as I don’t use them when including the file.

== What happens if I include my lib with all these tests?
Nothing. It won’t hurt you.

== What happens if I want to test a script that should be called from
lazytest is primarily for the testing of libraries, but since it only
the tests when you pass the “test” option to the script that should not
affect scripts that don’t use “test” as keyword.

== Future
I am currently fighting with the profiler to have let there be a ‘-p
profiling option.

But it frequently conflicts with my error handling and I have to dig
in it.

There will be some other testing tools to allow automagical
checking and datasoup checking.
This will be part of lazytest some day.

== Where may I find a complete example?
Look at example.rb.

Project Website:
Contact: [email protected]


Cool stuff, I like it, thanks :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs