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>
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 property is set and holds a certain value as substring.
Attribute | Description | Required |
name | Name of the property. | Yes |
value | Expected substring value. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected property 'name' to contain 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 doesn't contain bar" if the property foo doesn't contain the value bar regardless of case:
<assertPropertyContains message="foo doesn't contain 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 file="${ant.home}/lib/ant.jar"/>
Asserts that a given file does not exist.
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 file="${ant.home}/lib/ant.jar"/>
Since AntUnit 1.2
Asserts that a given resource exists. This was intended as a
generalization of assertFileExists
but still really
only works for file resources.
Use assertNestedResourceExists
or assertRefResourceExists
for non-filesystem
resources.
Attribute | Description | Required |
resource | Location of the resource. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected resource 'resource' to exist". | No. |
Make the build fail if the resource ${ant.home}/lib/ant.jar doesn't exist:
<assertResourceExists resource="${ant.home}/lib/ant.jar"/>
assertResourceExists
relies on Ant 1.8.0 or later,
it doesn't work with Ant 1.7.x. You can simulate the assertion
using the resourceExists
condition
and assertTrue
, for example
<au:assertTrue message="Expected resource '${ant.home}/lib/ant.jar' to exist"> <au:resourceExists> <file file="${ant.home}/lib/ant.jar"/> </au:resourceExists> </au:assertTrue>
Since AntUnit 1.3
Asserts that a resource given by its id exists.
Attribute | Description | Required |
refid | Reference to a resource defined inside the project. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected resource 'refid' to exist". | No. |
Make the build fail if the resource ${ant.home}/lib/ant.jar doesn't exist:
<file file="${ant.home}/lib/ant.jar" id="ant.jar"/> <assertRefResourceExists refid="ant.jar"/>
assertRefResourceExists
relies on Ant 1.8.0 or later,
it doesn't work with Ant 1.7.x.
Since AntUnit 1.3
Asserts that a resource given as nested element exists.
Attribute | Description | Required |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected resource to exist". | No. |
Make the build fail if the resource ${ant.home}/lib/ant.jar doesn't exist:
<assertNestedResourceExists> <file file="${ant.home}/lib/ant.jar"/> </assertNestedResourceExists>
assertNestedResourceExists
relies on Ant 1.8.0 or later,
it doesn't work with Ant 1.7.x.
Since AntUnit 1.2
Asserts that a given resource does not exist. This was
intended as a generalization
of assertFileDoesntExist
but still really only
works for file resources.
Use assertNestedResourceDoesntExist
or assertRefResourceDoesntExist
for non-filesystem
resources.
Attribute | Description | Required |
resource | Location of the resource. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Didn't expect resource 'resource' to exist". | No. |
Make the build fail if the resource ${ant.home}/lib/ant.jar exists:
<assertResourceDoesntExist resource="${ant.home}/lib/ant.jar"/>
assertResourceDoesntExist
relies on Ant 1.8.0 or later,
it doesn't work with Ant 1.7.x. You can simulate the assertion
using the resourceExists
condition
and assertFalse
, for example
<au:assertFalse message="Didn't expect resource '${ant.home}/lib/ant.jar' to exist"> <au:resourceExists> <file file="${ant.home}/lib/ant.jar"/> </au:resourceExists> </au:assertFalse>
Since AntUnit 1.3
Asserts that a resource given by its id exists.
Attribute | Description | Required |
refid | Reference to a resource defined inside the project. | Yes |
message | Message for the exception if the condition doesn't hold true. Defaults to "Didn't expect resource 'refid' to exist". | No. |
Make the build fail if the resource ${ant.home}/lib/ant.jar exists:
<file file="${ant.home}/lib/ant.jar" id="ant.jar"/> <assertRefResourceDoesntExist refid="ant.jar"/>
assertRefResourceDoesntExist
relies on Ant 1.8.0 or later,
it doesn't work with Ant 1.7.x.
Since AntUnit 1.3
Asserts that a resource given as nested element exists.
Attribute | Description | Required |
message | Message for the exception if the condition doesn't hold true. Defaults to "Didn't expect resource to exist". | No. |
Make the build fail if the resource ${ant.home}/lib/ant.jar exists:
<assertNestedResourceDoesntExist> <file file="${ant.home}/lib/ant.jar"/> </assertNestedResourceDoesntExist>
assertNestedResourceDoesntExist
relies on Ant 1.8.0 or later,
it doesn't work with Ant 1.7.x.
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 a string matches a given regular expression.
Attribute | Description | Required |
string | The string to test. | Yes |
pattern | The pattern to test the string against. | Yes |
casesensitive | Perform a case sensitive match. Default is true. | No. |
multiline | Perform a multi line match. Default is false. | No. |
singleline | This allows '.' to match new lines. SingleLine is not to be confused with multiline, SingleLine is a perl regex term, it corresponds to dotall in java regex. Default is false. | No. |
Make the build fail if the property abc does not contain "abc" regardless of case:
<assertMatches string="${abc}" pattern="abc" casesensitive="false"/>
Asserts that a string doesn't match a given regular expression.
Attribute | Description | Required |
string | The string to test. | Yes |
pattern | The pattern to test the string against. | Yes |
casesensitive | Perform a case sensitive match. Default is true. | No. |
multiline | Perform a multi line match. Default is false. | No. |
singleline | This allows '.' to match new lines. SingleLine is not to be confused with multiline, SingleLine is a perl regex term, it corresponds to dotall in java regex. Default is false. | No. |
Make the build fail if the property abc contains "abc" regardless of case:
<assertDoesntMatch string="${abc}" pattern="abc" casesensitive="false"/>
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 search 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 |
mergeLines | Whether to merge messages into a single line or split them into multiple lines. since AntUnit 1.3 | No, defaults
to true |
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 search 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 |
mergeLines | Whether to merge messages into a single line or split them into multiple lines. since AntUnit 1.3 | No, defaults
to true |
Asserts that a resource's content includes a given string.
This task anly really works for filesystem resources.
Use assertRefResourceContains
when using non-file
resources.
Attribute | Description | Required |
resource | Location of the resource to load. | Yes |
value | The text to search for. | Yes |
casesensitive | Perform a case sensitive match. Default is true. | No. |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected resource 'resource' to contain value 'value' but was 'content of resource'". | No. |
Since AntUnit 1.3
Asserts that a resource's content includes a given string.
Attribute | Description | Required |
refid | Reference to a resource defined inside the project. | Yes |
value | The text to search for. | Yes |
casesensitive | Perform a case sensitive match. Default is true. | No. |
message | Message for the exception if the condition doesn't hold true. Defaults to "Expected resource 'refeid' to contain value 'value'." | No. |
Asserts that a resource's content doesn't include a given string.
This task anly really works for filesystem resources.
Use assertRefResourceDoesntContain
when using non-file
resources.
Attribute | Description | Required |
resource | Location of the resource to load. | Yes |
value | The text to search for. | Yes |
casesensitive | Perform a case sensitive match. Default is true. | No. |
message | Message for the exception if the condition doesn't hold true. Defaults to "Didn't expect resource 'resource' to contain value 'value' but was 'content of resource'". | No. |
Since AntUnit 1.3
Asserts that a resource's content doesn't include a given string.
Attribute | Description | Required |
refid | Reference to a resource defined inside the project. | Yes |
value | The text to search for. | Yes |
casesensitive | Perform a case sensitive match. Default is true. | No. |
message | Message for the exception if the condition doesn't hold true. Defaults to "Didn't expect resource 'refid' to contain value 'value'". | No. |