Package org.apache.ant.antunit.listener
Class BaseAntUnitListener
- java.lang.Object
-
- org.apache.ant.antunit.listener.BaseAntUnitListener
-
- All Implemented Interfaces:
AntUnitListener
- Direct Known Subclasses:
FailureAntUnitListener
,PlainAntUnitListener
,XMLAntUnitListener
public abstract class BaseAntUnitListener extends java.lang.Object implements AntUnitListener
A test listener for <antunit> modeled aftern the Plain JUnit test listener that is part of Ant.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BaseAntUnitListener.AntUnitLogLevel
class
BaseAntUnitListener.LogGrabber
static class
BaseAntUnitListener.SendLogTo
-
Field Summary
Fields Modifier and Type Field Description private org.apache.tools.ant.Project
currentTest
protected int
errorCount
keeps track of the numer of executed targets, the failures an errors.private java.lang.String
extension
Extension for report files.protected int
failureCount
keeps track of the numer of executed targets, the failures an errors.private BaseAntUnitListener.AntUnitLogLevel
logLevel
The minimum level a log message must be logged at to be included in the output.private BaseAntUnitListener.SendLogTo
logTo
Where to send log.protected static java.text.NumberFormat
nf
Formatter for timings.private org.apache.tools.ant.Task
parentTask
protected int
runCount
keeps track of the numer of executed targets, the failures an errors.protected long
start
time for the starts of the current test-suite and test-target.protected long
testStart
time for the starts of the current test-suite and test-target.private java.io.File
toDir
Directory to write reports to.
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseAntUnitListener(BaseAntUnitListener.SendLogTo defaultReportTarget, java.lang.String extension)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addError(java.lang.String target, java.lang.Throwable ae)
Invoked if any error other than a failed assertion occured during execution.void
addFailure(java.lang.String target, AssertionFailedException ae)
Invoked if an assert tasked caused an error during execution.protected void
close(java.io.OutputStream out)
protected org.apache.tools.ant.Project
getCurrentTestProject()
protected org.apache.tools.ant.Location
getLocation(java.lang.Throwable t)
protected java.io.OutputStream
getOut(java.lang.String buildFile)
protected java.io.File
getToDir()
Directory to write reports to.protected void
messageLogged(org.apache.tools.ant.BuildEvent event)
Gets messages from the project running the test target if their level is at least of the level specified withsetLogLevel
.protected java.lang.String
normalize(java.lang.String buildFile)
Turns the build file name into something that vaguely looks like a Java classname.void
setCurrentTestProject(org.apache.tools.ant.Project p)
Set a reference to the Project instance currently executing the test target.void
setLogLevel(BaseAntUnitListener.AntUnitLogLevel l)
Sets the minimum level a log message must be logged at to be included in the output.void
setParentTask(org.apache.tools.ant.Task t)
Set a reference to the AntUnit task executing the tests, this provides access to the containing project, target or Ant's logging system.protected void
setSendLogTo(BaseAntUnitListener.SendLogTo logTo)
Where to send the test report.void
setToDir(java.io.File f)
Sets the directory to write test reports to.void
startTest(java.lang.String target)
Invoked before a test target gets executed.void
startTestSuite(org.apache.tools.ant.Project testProject, java.lang.String buildFile)
Invoked once per build file, before any targets get executed.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.ant.antunit.AntUnitListener
endTest, endTestSuite
-
-
-
-
Field Detail
-
nf
protected static final java.text.NumberFormat nf
Formatter for timings.
-
toDir
private java.io.File toDir
Directory to write reports to.
-
extension
private java.lang.String extension
Extension for report files.
-
logTo
private BaseAntUnitListener.SendLogTo logTo
Where to send log.
-
parentTask
private org.apache.tools.ant.Task parentTask
-
runCount
protected int runCount
keeps track of the numer of executed targets, the failures an errors.
-
failureCount
protected int failureCount
keeps track of the numer of executed targets, the failures an errors.
-
errorCount
protected int errorCount
keeps track of the numer of executed targets, the failures an errors.
-
start
protected long start
time for the starts of the current test-suite and test-target.
-
testStart
protected long testStart
time for the starts of the current test-suite and test-target.
-
currentTest
private org.apache.tools.ant.Project currentTest
-
logLevel
private BaseAntUnitListener.AntUnitLogLevel logLevel
The minimum level a log message must be logged at to be included in the output.
-
-
Constructor Detail
-
BaseAntUnitListener
protected BaseAntUnitListener(BaseAntUnitListener.SendLogTo defaultReportTarget, java.lang.String extension)
-
-
Method Detail
-
getToDir
protected final java.io.File getToDir()
Directory to write reports to.- Returns:
- directory to write reports to
-
setToDir
public void setToDir(java.io.File f)
Sets the directory to write test reports to.- Parameters:
f
- directory to write reports to
-
setSendLogTo
protected void setSendLogTo(BaseAntUnitListener.SendLogTo logTo)
Where to send the test report.- Parameters:
logTo
- where to send the test report
-
setParentTask
public void setParentTask(org.apache.tools.ant.Task t)
Description copied from interface:AntUnitListener
Set a reference to the AntUnit task executing the tests, this provides access to the containing project, target or Ant's logging system.- Specified by:
setParentTask
in interfaceAntUnitListener
- Parameters:
t
- the parent task
-
startTestSuite
public void startTestSuite(org.apache.tools.ant.Project testProject, java.lang.String buildFile)
Description copied from interface:AntUnitListener
Invoked once per build file, before any targets get executed.- Specified by:
startTestSuite
in interfaceAntUnitListener
- Parameters:
testProject
- the projectbuildFile
- the build file
-
close
protected final void close(java.io.OutputStream out)
-
startTest
public void startTest(java.lang.String target)
Description copied from interface:AntUnitListener
Invoked before a test target gets executed.- Specified by:
startTest
in interfaceAntUnitListener
- Parameters:
target
- name of the target
-
addFailure
public void addFailure(java.lang.String target, AssertionFailedException ae)
Description copied from interface:AntUnitListener
Invoked if an assert tasked caused an error during execution.- Specified by:
addFailure
in interfaceAntUnitListener
- Parameters:
target
- name of the targetae
- the failure
-
addError
public void addError(java.lang.String target, java.lang.Throwable ae)
Description copied from interface:AntUnitListener
Invoked if any error other than a failed assertion occured during execution.- Specified by:
addError
in interfaceAntUnitListener
- Parameters:
target
- name of the targetae
- the error
-
getOut
protected final java.io.OutputStream getOut(java.lang.String buildFile)
-
normalize
protected final java.lang.String normalize(java.lang.String buildFile)
Turns the build file name into something that vaguely looks like a Java classname. Close enough to be suitable for junitreport.- Parameters:
buildFile
- the test file name- Returns:
- the normalized name
-
getLocation
protected final org.apache.tools.ant.Location getLocation(java.lang.Throwable t)
-
setCurrentTestProject
public void setCurrentTestProject(org.apache.tools.ant.Project p)
Description copied from interface:AntUnitListener
Set a reference to the Project instance currently executing the test target.This provides access to the logging system or the properties of the project under test. Note that different test targets will be executed in different Ant Project instances.
- Specified by:
setCurrentTestProject
in interfaceAntUnitListener
- Parameters:
p
- the test project
-
getCurrentTestProject
protected org.apache.tools.ant.Project getCurrentTestProject()
-
setLogLevel
public void setLogLevel(BaseAntUnitListener.AntUnitLogLevel l)
Sets the minimum level a log message must be logged at to be included in the output.- Parameters:
l
- minimum level
-
messageLogged
protected void messageLogged(org.apache.tools.ant.BuildEvent event)
Gets messages from the project running the test target if their level is at least of the level specified withsetLogLevel
.This implementation is empty.
- Parameters:
event
- the logged message
-
-