Lemon

Method Index [+]

Quicksearch
[Validate]
Generated with WebRI NewFish 1.2.1

Lemon

DESCRIPTION

Lemon is a Unit Testing Framework that enforces a test case construction mirroring the class/module and method design of the target system. Arguably this promotes the proper technique for unit testing and helps ensure good test coverage.

The difference between unit testing and functional testing, and all other forms of testing for that matter, lies in where the concern lies. The concern of unit testing are the concerns of unit tests — the individual methods.

HOW TO USE

Writing Tests

Say our library ‘mylib.rb’ consists of the class X:

  class X
    def a; "a"; end
  end

The simplist test case would be written as follows:

  Covers 'mylib'

  TestCase X do
    Unit :a => "method #a does something expected" do
      x = X.new
      x.a.assert.is_a? String
    end
  end

The Covers method works just like require with the exception that loading the file does not occur until just before the tests are run. This allows Lemon to cacluate accurate coverage reports.

As tests grow, we might need to organize them into special concerns. For this Lemon provides the #Concern method.

  Covers 'mylib'

  TestCase X do
    Concern "Description of a concern that the following unit tests address."

    Unit :a => "method #a does something expected" do
      x = X.new
      x.a.assert.is_a? String
    end
  end

Running Tests

To run tests use the lemon command-line utility.

  $ lemon test/cases/name_case.rb

Normal output is typical dot-progress. For verbose output, use the --verbose or -v option.

  $ lemon -v test/cases/name_case.rb

Checking Test Coverage

Lemon can check test coverage by loading your target system and comparing it to your tests. To do this suppy the lemon command the --coverage or -c option.

  $ lemon --coverage -Ilib test/cases/

Generating Test Skeletons

Because of the one to one correspondance of case-unit to class-method, Lemon can also generate test scaffolding for previously written code. To do this, use the --generate or -g option and provide the lib location, or files, of the scripts for which to generate test scaffolding, and the output location for the test scripts.

  $ lemon --generate -Ilib test/cases/

Generating test case scaffodling from code will undoubtedly strike test-driven developers as a case of putting the cart before the horse. However, it is not unreasonable to argue that high-level, behavior-driven, functional testing frameworks, such as Q.E.D. and Cucumber are better suited to test-first methodologies. While test-driven development can obviously be done with Lemon, unit-testing is more appropriate for testing specific, critical protions of code, or for achieving full test coverage for mission critical applications.

COPYRIGHT

(MIT License)

Copyright © 2009 Thomas Sawyer

See LICENSE file for details.