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
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. |
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.
Exclude the specified tests. This method accepts multiple arguments and returns self. See include for the type of arguments you can use.
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
Executes by the compile task to copy resource files over. See Project#resources.
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:
project (:each), or don't fork at all (false).
form of environment variables.
Specify artifacts (specs, tasks, files, etc) to include in the dependencies list when compiling and running tests.