Class Buildr::TestTask
In: lib/buildr/core/test.rb  (CVS)
Parent: Rake::Task

The test task controls the entire test lifecycle.

You can use the test task in three ways. You can access and configure specific test tasks, e.g. enhance the compile task, or run code during setup/teardown.

You can use convenient methods that handle the most common settings. For example, add dependencies using with, or include only specific tests using include.

You can also enhance this task directly. This task will first execute the compile task, followed by the setup task, run the unit tests, any other enhancements, and end by executing teardown.

The test framework is determined based on the available test files, for example, if the test cases are written in Java, then JUnit is selected as the test framework. You can also select a specific test framework, for example, to use TestNG instead of JUnit:

  test.using :testng

Methods

Attributes

dependencies  [RW]  The dependencies used for running the tests. Includes the compiled files (compile.target) and their dependencies. Will also include anything you pass to with, shared between the testing compile and run dependencies.
failed_tests  [R]  After running the task, returns all the tests that failed, empty array if all tests passed.
forced_need  [RW]  Whether the tests are forced
options  [R]  Returns various test options.
passed_tests  [R]  After running the task, returns all the tests that passed, empty array if no tests passed.
project  [R]  The project this task belongs to.
tests  [R]  After running the task, returns all tests selected to run, based on availability and include/exclude pattern.

Public Class methods

Used by the test/integration rule to clear all previously included/excluded tests.

Used by the test/integration to exclude specific tests

Used by the test/integration to include specific tests

Public Instance methods

Deprecated: Use tests instead.

Deprecated: Use dependencies instead.

Deprecated: Use dependencies= instead.

Clear all test includes and excludes and returns self

The compile task is similar to the Project‘s compile task. However, it compiles all files found in the src/test/{source} directory into the target/test/{code} directory. This task is executed by the test task before running any tests.

Once the project definition is complete, all dependencies from the regular compile task are copied over, so you only need to specify dependencies specific to your tests. You can do so by calling with on the test task. The dependencies used here are also copied over to the junit task.

Default options already set on each test task.

Exclude the specified tests. This method accepts multiple arguments and returns self. See include for the type of arguments you can use.

We record the list of failed tests for the current framework in this file.

Returns the test framework, e.g. :junit, :testng.

Include only the specified tests. Unless specified, the default is to include all tests identified by the test framework. This method accepts multiple arguments and returns self.

Tests are specified by their full name, but you can use glob patterns to select multiple tests, for example:

  test.include 'com.example.FirstTest'  # FirstTest only
  test.include 'com.example.*'          # All tests under com/example
  test.include 'com.example.Module*'    # All tests starting with Module
  test.include '*.{First,Second}Test'   # FirstTest, SecondTest

We read the last test failures if any and return them.

Test frameworks that can produce reports, will write them to this directory.

This is framework dependent, so unless you use the default test framework, call this method after setting the test framework.

Executes by the compile task to copy resource files over. See Project#resources.

Returns the setup task. The setup task is executed at the beginning of the test task, after compiling the test files.

Returns the teardown task. The teardown task is executed at the end of the test task.

Sets various test options from a hash and returns self. For example:

  test.using :fork=>:each, :properties=>{ 'url'=>'http://localhost:8080' }

Can also be used to select the test framework, or to run these tests as integration tests. For example:

  test.using :testng
  test.using :integration

The :fail_on_failure option specifies whether the task should fail if any of the tests fail (default), or should report the failures but continue running the build (when set to false).

All other options depend on the capability of the test framework. These options should be used the same way across all frameworks that support them:

  • :fork — Fork once for each project (:once, default), for each test in each
      project (:each), or don't fork at all (false).
    
  • :properties — Properties pass to the test, e.g. in Java as system properties.
  • :environment — Environment variables. This hash is made available in the
      form of environment variables.
    

Specify artifacts (specs, tasks, files, etc) to include in the dependencies list when compiling and running tests.

Protected Instance methods

Returns true if the specified test name matches the inclusion/exclusion pattern. Used to determine which tests to execute.

Limit running tests to specific list.

Limit running tests to those who failed the last time.

Runs the tests using the selected test framework.

[Validate]