This Ant library also provides a couple of pre-defined assertions that are specializations of the <assertTrue> task.
Negates <assertTrue>. Supports the same attributes and nested elements as <assertTrue> but makes the build fail if the nested condition is true.
Make the build fail with the message "foo is bar" if the property foo has the value bar:
<assertFalse message="foo is bar"> <equals arg1="${foo}" arg2="bar"/> </assertFalse message="foo is bar">
Asserts that its two arguments are equal.
Attribute | Description | Required |
expected | First string to test. | Yes |
actual | Second string to test. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected 'expected' but was 'actual'". | No. |
casesensitive | Perform a case sensitive comparision. Default is true. | No |
Make the build fail with the message "foo is not bar" if the property foo doesn't hold the value bar regardless of case:
<assertEquals message="foo is not bar" expected="bar" actual="${foo}" casesensitive="false"/>
Asserts that a property has a value.
Attribute | Description | Required |
name | Name of the property. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected property 'name'". | No. |
Make the build fail with the message "Expected property 'foo'" if the property foo is not defined:
<assertPropertySet name="foo"/>
Asserts that a given property is set and holds a certain value.
Attribute | Description | Required |
name | Name of the property. | Yes |
value | Expected value. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected property 'name' to have value 'value' but was 'value of property name'". | No. |
casesensitive | Perform a case sensitive comparision. Default is true. | No |
Make the build fail with the message "foo is not bar" if the property foo doesn't hold the value bar regardless of case:
<assertPropertyEquals message="foo is not bar" value="bar" name="foo" casesensitive="false"/>
Asserts that a given file exists.
Attribute | Description | Required |
file | Location of the file. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected file 'file' to exist". | No. |
Make the build fail if the file ${ant.home}/lib/ant.jar doesn't exist:
<assertFileExists name="${ant.home}/lib/ant.jar"/>
Asserts that a given file does not exists.
Attribute | Description | Required |
file | Location of the file. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Didn't expect file 'file' to exist". | No. |
Make the build fail if the file ${ant.home}/lib/ant.jar exists:
<assertFileDoesntExist name="${ant.home}/lib/ant.jar"/>
Asserts that a dest file is more recent than the source file.
Attribute | Description | Required |
src | source file. | Yes |
dest | dest file. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected 'dest' to be more recent than 'src'". | No. |
Make the build fail if the file ${ant.home}/lib/ant.jar is more recent than the current build file:
<assertDestIsUptodate dest="${ant.file}" src="${ant.home}/lib/ant.jar"/>
Asserts that a source file is more recent than the dest file.
Attribute | Description | Required |
src | source file. | Yes |
dest | dest file. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected 'src' to be more recent than 'dest'". | No. |
Make the build fail if the file ${ant.home}/lib/ant.jar is older than the current build file:
<assertDestIsOutofdate dest="${ant.file}" src="${ant.home}/lib/ant.jar"/>
Asserts that two files have the same content.
Attribute | Description | Required |
expected | first file. | Yes |
actual | second file. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected files 'expected' and 'actual' to match". | No. |
Make the build fail if the file build.xml and backups/build.xml differ.
<assertFilesMatch expected="backups/build.xml" actual="build.xml"/>
Asserts that two files have different content.
Attribute | Description | Required |
expected | first file. | Yes |
actual | second file. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected files 'expected' and 'actual' to differ". | No. |
Make the build fail if the file build.xml and backups/build.xml match.
<assertFilesDiffer expected="backups/build.xml" actual="build.xml"/>
Asserts that a reference has a value.
Attribute | Description | Required |
refid | Id of the reference. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected reference 'id'". | No. |
Make the build fail with the message "Expected reference 'foo'" if the reference foo is not defined:
<assertReferenceSet name="foo"/>
Asserts that a reference has a value of a given type.
Attribute | Description | Required |
refid | Id of the reference. | Yes |
type | Name of the data type or task this reference is expected to be. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected reference 'id' to be a 'type'". | No. |
Make the build fail if the reference classpath has not been set or doesn't point to a <path>.
<assertReferenceIsType refid="classpath" type="path"/>
Asserts that the build log contains a given message.
Only works in the context of an <antunit> task.
Attribute | Description | Required |
text | The text to serach for. | Yes |
level | The level the message should have been logged at - the task will also look into more severe levels. One of "error", "warning", "info", "verbose", "debug". | No |
Asserts that the build log doesn't contain a given message.
Only works in the context of an <antunit> task.
Attribute | Description | Required |
text | The text to serach for. | Yes |
level | The level the message should have been logged at - the task will also look into more severe levels. One of "error", "warning", "info", "verbose", "debug". | No |