|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--junit.framework.Assert | +--junit.framework.TestCase | +--freemarker.testcase.AbstractTestCase
Abstract class used to implement test cases for FreeMarker. This
class is an abstract subclass of the TestCase
class
provided by JUnit. All FM-Classic testcases are subclassed off
this class.
This class offers functionality to its subclasses to ease testing where a template is read in, and then written out with a specific data model. Passing the test means that the resulting page matches a given reference text. This class also supports the creation of those reference texts.
To write a new test by subclassing this class, you'll want to do the following:
templates
directory located immediately below
this directory. Say it is called test-foo.html
.AbstractTestCase
, and in the
setUp
method, call setUpFile("test-foo.html")
.
This will initialize several protected instance variables as
follows: m_aReferenceText
will contain the contents of
file "reference/test-foo.html", m_aTemplateText
will
contain the contents of file "templates/test-foo.html", and
m_aFilename
will contain the string "test-foo.html".
You can also set up a data model, as per usual JUnit practice.m_aTemplateText
.
Process this with your model, and send the output to a
StringWriter
. Finally, call the
showTestResults
method, passing in the
m_aReferenceText
and the results of your test (from your
StringWriter
object). This will signal an error
if there is a difference.
Field Summary | |
protected java.lang.String |
m_aFilename
The filename of the reference text if the text doesn't match. |
protected java.lang.String |
m_aReferenceText
The reference text against which the test case output is compared. |
protected java.lang.String |
m_aTemplateText
The raw, unparsed text of the template. |
Constructor Summary | |
AbstractTestCase(java.lang.String aTestName)
Creates new AbstractTestCase, with a filename from which to populate reference text and template text. |
Method Summary | |
protected java.lang.String |
getReferenceText(java.lang.String aFilename)
Gets the reference text for the implementing test class. |
protected java.lang.String |
getTemplateText(java.lang.String aFilename)
Gets the template text for the implementing test class. |
protected java.lang.String |
getTestcasePath()
Retrieve the root path of the FM-Classic distribution from a properties file. |
protected java.lang.String |
getTextFromFile(java.lang.String aFilename)
Reads text from a file. |
protected void |
isTextIdentical(java.lang.String aReference,
java.lang.String aOutput)
Performs the test on the output text to indicate whether the text is identical to the reference text. |
protected void |
setUpFiles(java.lang.String aFilename)
Sets up the reference and template files to be used for the test. |
protected void |
showTestResults(java.lang.String aReference,
java.lang.String aOutput)
Verify that the output of a test is identical to the reference text. |
protected void |
writeText(java.lang.String aFilename,
java.lang.String aText)
Writes text to a given filename. |
Methods inherited from class junit.framework.TestCase |
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString |
Methods inherited from class junit.framework.Assert |
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.lang.String m_aReferenceText
protected java.lang.String m_aTemplateText
protected java.lang.String m_aFilename
Constructor Detail |
public AbstractTestCase(java.lang.String aTestName)
Method Detail |
protected void setUpFiles(java.lang.String aFilename)
aFilename
- the filename to be used for retrieving the reference
text and the templateprotected java.lang.String getTextFromFile(java.lang.String aFilename) throws java.io.IOException
aFilename
- the filename to read fromprotected java.lang.String getReferenceText(java.lang.String aFilename) throws java.io.IOException
aFilename
- the filename of the text to be retrieved, relative
to the reference
directoryprotected java.lang.String getTemplateText(java.lang.String aFilename) throws java.io.IOException
aFilename
- the filename of the text to be retrieved, relative
to the template
directoryprotected void isTextIdentical(java.lang.String aReference, java.lang.String aOutput) throws TestCaseException
aReference
- the reference text to be comparedaOutput
- the text that was generated by the test caseTestCaseException
- the text is in some way differentprotected void showTestResults(java.lang.String aReference, java.lang.String aOutput)
aReference
- the reference textaOutput
- the output from the testprotected void writeText(java.lang.String aFilename, java.lang.String aText) throws java.io.IOException
aFilename
- the name of the file to be writtenaText
- the text to be written to the filejava.io.IOException
- the file could not be writtenprotected java.lang.String getTestcasePath() throws java.io.IOException
java.io.IOException
- the testcase.properties
file could
not be read
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |