More Assertion Tasks

This Ant library also provides a couple of pre-defined assertions that are specializations of the <assertTrue> task.

AssertFalse

Description

Negates <assertTrue>. Supports the same attributes and nested elements as <assertTrue> but makes the build fail if the nested condition is true.

Examples

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">
    

assertEquals

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

Examples

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"/>
    

assertPropertySet

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.

Examples

Make the build fail with the message "Expected property 'foo'" if the property foo is not defined:

      <assertPropertySet name="foo"/>
    

assertPropertyEquals

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

Examples

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"/>
    

assertFileExists

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.

Examples

Make the build fail if the file ${ant.home}/lib/ant.jar doesn't exist:

      <assertFileExists name="${ant.home}/lib/ant.jar"/>
    

assertFileDoesntExists

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.

Examples

Make the build fail if the file ${ant.home}/lib/ant.jar exists:

      <assertFileDoesntExist name="${ant.home}/lib/ant.jar"/>
    

assertDestIsUpToDate

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.

Examples

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"/>
    

assertDestIsOutofDate

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.

Examples

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"/>
    

assertFilesMatch

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.

Example

Make the build fail if the file build.xml and backups/build.xml differ.

      <assertFilesMatch expected="backups/build.xml" actual="build.xml"/>
    

assertFilesDiffer

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.

Example

Make the build fail if the file build.xml and backups/build.xml match.

      <assertFilesDiffer expected="backups/build.xml" actual="build.xml"/>
    

assertReferenceSet

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.

Examples

Make the build fail with the message "Expected reference 'foo'" if the reference foo is not defined:

      <assertReferenceSet name="foo"/>
    

assertReferenceIsType

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.

Examples

Make the build fail if the reference classpath has not been set or doesn't point to a <path>.

      <assertReferenceIsType refid="classpath" type="path"/>
    

assertLogContains

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

assertLogDoesntContain

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