Organizando las pruebas

  1. Tests for a particular unit of code are grouped together into a test case, which is a subclass of Test/Unit/TestCase.

  2. Assertions are gathered in tests, member functions for the test case whose names start with test_.

  3. When the test case is executed or required, Test/Unit will iterate through all of the tests (finding all of the member functions which start with test_ using reflection) in the test case, and provide the appropriate feedback.

  4. Test case classes can be gathered together into test suites which are Ruby files which require other test cases:
      # File: ts_allTheTests.rb
      require 'test/unit'
      require 'testOne'
      require 'testTwo'
      require 'testThree'
    In this way, related test cases can be naturally grouped.

  5. Further, test suites can contain other test suites, allowing the construction of a hierarchy of tests.
  6. This structure provides relatively fine-grained control over testing.

    1. Individual tests can be run from a test case
    2. a full test case can be run stand-alone,
    3. a test suite containing multiple cases can be run,
    4. or a suite of suites can run, spanning many test cases.

Convenciones con respecto a los Nombres

The author of Test/Unit, Nathaniel Talbott, suggests starting the names of test cases with tc_ and the names of test suites with ts_

Ejecución de pruebas específicas

It's possible to run just one (or more) tests out of a full test case:
>> ruby -w tc_simpleNumber2.rb --name test_typecheck 
Loaded suite tc_simpleNumber2
Finished in 0.003401 seconds.
1 tests, 1 assertions, 0 failures, 0 errors

It is also possible to run all tests whose names match a given pattern:

>> ruby -w tc_simpleNumber2.rb --name /test_type.*/ 
Loaded suite tc_simpleNumber2
Finished in 0.003401 seconds.
1 tests, 1 assertions, 0 failures, 0 errors

Opciones en Línea de Comandos

unittestingpoint/examples(master)]$ ruby -I. tc_point_1.rb --help
Usage: tc_point_1 [options]
minitest options:
    -h, --help                       Display this help.
    -s, --seed SEED                  Sets random seed
    -v, --verbose                    Verbose. Show progress processing files.
    -n, --name PATTERN               Filter test names on pattern.
        --jobs-status [TYPE]         Show status of jobs every file; Disabled when --jobs isn't specified.
    -j, --jobs N                     Allow run tests with N jobs at once
        --separate                   Restart job process after one testcase has done
        --retry                      Retry running testcase when --jobs specified
        --no-retry                   Disable --retry
        --ruby VAL                   Path to ruby; It'll have used at -j option
    -q, --hide-skip                  Hide skipped tests
        --show-skip                  Show skipped tests
        --color[=WHEN]               colorize the output.  WHEN defaults to 'always'
                                     or can be 'never' or 'auto'.
        --tty[=WHEN]                 force to output tty control.  WHEN defaults to 'yes'
                                     or can be 'no'.
    -b, --basedir=DIR                Base directory of test suites.
    -x, --exclude PATTERN            Exclude test files on pattern.
    -Idirectory                      Add library load path
        --[no-]gc-stress             Set GC.stress as true

Casiano Rodriguez León 2015-01-07