public class OutputTester extends Object
Constructor and Description |
---|
OutputTester(Class<?> testRoot,
String expectedOutputsDirPath)
Creates an output tester to validate outputs produced by test methods of a given class.
|
OutputTester(Class<?> testRoot,
String expectedOutputsDirPath,
String expectedOutputEncoding)
Creates an output tester to validate outputs produced by test methods of a given class.
|
OutputTester(String expectedOutputsDirPath)
Creates an output tester to validate outputs produced by test methods of a subclass
|
OutputTester(String expectedOutputsDirPath,
String expectedOutputEncoding)
Creates an output tester to validate outputs produced by test methods of a subclass
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Discards any output stored in the internal buffer.
|
File |
getResourceDir()
Returns the project's actual resource directory, where the expected output files are located.
|
String |
getTestResourcesFolder()
Returns the project's test resources folder (relative to the project root), where the expected output files are located.
|
boolean |
getUpdateExpectedOutputs()
Returns a flag indicating whether all tests of the test class should have their outputs updated.
|
boolean |
isDumpMismatchedOutputToFile()
Indicates whether the output produced by a given test method should be written into a temporary file.
|
boolean |
isNormalizeLineSeparators()
Indicates whether line separators in both produced and expected outputs will be normalized (i.e.
|
void |
print(Object contents)
Appends some content to the output.
|
void |
print(StringBuilder out,
Object contents)
Appends some content to the output.
|
void |
printAndDontValidate(CharSequence output,
Object... methodArgs)
Prints the result to the standard output without validating its contents
|
void |
printAndDontValidate(Object... methodArgs)
Prints the result to the standard output without validating its contents
|
void |
printAndValidate(CharSequence output,
Object... methodArgs)
Prints the result to the standard output and validates it against the expected output
stored in {expectedOutputsDirPath}/{test_class_name}/{test_method_name}
|
void |
printAndValidate(Object... methodArgs)
Prints the result to the standard output and validates it against the expected output
stored in {expectedOutputsDirPath}/{test_class_name}/{test_method_name}
|
void |
println()
Appends a newline to the output
|
void |
println(Object contents)
Appends some content to the output and adds a newline at the end.
|
void |
println(StringBuilder out)
Appends a newline to the output
|
void |
println(StringBuilder out,
Object contents)
Appends some content to the output and adds a newline at the end.
|
void |
setDumpMismatchedOutputToFile(boolean dumpMismatchedOutputToFile)
Defines whether the output produced by a given test method should be written into a temporary file.
|
void |
setNormalizeLineSeparators(boolean normalizeLineSeparators)
Enables/disables normalization of line separators.
|
void |
setResourceDir(File resourceDir)
Defines the project's actual resource directory, where the expected output files are located.
|
void |
setTestResourcesFolder(String testResourcesFolder)
Defines the project's test resources folder (relative to the project root), where the expected output files are located.
|
void |
setUpdateExpectedOutputs(boolean updateExpectedOutputs)
Used to indicate when all tests of the test class should have their outputs updated.
|
void |
updateExpectedOutput(CharSequence output,
Object... methodArgs)
Updates or creates the expected output file under the given expected output directory.
|
void |
updateExpectedOutput(Object... methodArgs)
Updates or creates the expected output file under the given expected output directory.
|
void |
validate(CharSequence output,
Object... methodArgs)
Validates the result against the expected output
stored in {expectedOutputsDirPath}/{test_class_name}/{test_method_name}
|
void |
validate(Object... methodArgs)
Validates the result against the expected output
stored in {expectedOutputsDirPath}/{test_class_name}/{test_method_name}
|
public OutputTester(String expectedOutputsDirPath)
expectedOutputsDirPath
- the path to a file or classpath resource that contains the expected outputspublic OutputTester(String expectedOutputsDirPath, String expectedOutputEncoding)
expectedOutputsDirPath
- the path to a file or classpath resource that contains the expected outputsexpectedOutputEncoding
- the encoding of the files stored in the given pathpublic OutputTester(Class<?> testRoot, String expectedOutputsDirPath)
testRoot
- the test class whose test methods' outputs will be validatedexpectedOutputsDirPath
- the path to a file or classpath resource that contains the expected outputspublic OutputTester(Class<?> testRoot, String expectedOutputsDirPath, String expectedOutputEncoding)
testRoot
- the test class whose test methods' outputs will be validatedexpectedOutputsDirPath
- the path to a file or classpath resource that contains the expected outputsexpectedOutputEncoding
- the encoding of the files stored in the given pathpublic void setUpdateExpectedOutputs(boolean updateExpectedOutputs)
getUpdateExpectedOutputs()
method evaluates to true
, all calls to validate(Object...)
or printAndValidate(Object...)
will trigger the updateExpectedOutput(Object...)
method internally. No tests will fail but error messages will be
printed out to the standard output to remind users that the outputs are not being validated.updateExpectedOutputs
- flag to indicate whether all expected outputs of a test case should be updated.public boolean getUpdateExpectedOutputs()
true
,
all calls to validate(Object...)
or printAndValidate(Object...)
will trigger the
updateExpectedOutput(Object...)
method internally. No tests will fail but error messages will be
printed out to the standard output to remind users that the outputs are not being validated.true
to indicate whether all expected outputs of a test case should be updated, or false
if
the test case outputs will be validated.public void printAndDontValidate(CharSequence output, Object... methodArgs)
output
- the result of the test case.methodArgs
- arguments passed to the test method. Used when testing with data providerspublic void printAndDontValidate(Object... methodArgs)
methodArgs
- arguments passed to the test method. Used when testing with data providerspublic void printAndValidate(CharSequence output, Object... methodArgs)
output
- the result of the test case to be validated against the expected output.methodArgs
- arguments passed to the test method. Used when testing with data providerspublic void printAndValidate(Object... methodArgs)
methodArgs
- arguments passed to the test method. Used when testing with data providerspublic void validate(CharSequence output, Object... methodArgs)
output
- the result of the test case to be validated against the expected output.methodArgs
- arguments passed to the test method. Used when testing with data providerspublic void validate(Object... methodArgs)
methodArgs
- arguments passed to the test method. Used when testing with data providerspublic File getResourceDir()
updateExpectedOutput(Object...)
is called to determine where to update/create expected output files.public void setResourceDir(File resourceDir)
updateExpectedOutput(Object...)
is called to determine where to update/create expected output files.resourceDir
- project's resource directory.public String getTestResourcesFolder()
updateExpectedOutput(Object...)
is called to determine where to update/create expected output files, and getResourceDir()
evaluates to null
Defaults to "src/test/resources"public void setTestResourcesFolder(String testResourcesFolder)
updateExpectedOutput(Object...)
is called to determine where to update/create expected output files, and getResourceDir()
evaluates to null
;
Defaults to "src/test/resources"testResourcesFolder
- the test resources folder.public void updateExpectedOutput(Object... methodArgs)
methodArgs
- arguments passed to the test method. Used when testing with data providerspublic void updateExpectedOutput(CharSequence output, Object... methodArgs)
output
- the actual output whose contents will be used to generate/update the expected output file.methodArgs
- arguments passed to the test method. Used when testing with data providerspublic void println(StringBuilder out, Object contents)
out
- the output to have content appended to.contents
- the contents to be appendedpublic void println(Object contents)
contents
- the contents to be appendedpublic void println(StringBuilder out)
out
- the output to have a newline appendedpublic void println()
public void print(StringBuilder out, Object contents)
out
- the output to have content appended to.contents
- the contents to be appendedpublic void print(Object contents)
contents
- the contents to be appendedpublic void clear()
public boolean isNormalizeLineSeparators()
'\n'
).public void setNormalizeLineSeparators(boolean normalizeLineSeparators)
'\n'
.normalizeLineSeparators
- flag to enable or disable normalization of line separatorspublic boolean isDumpMismatchedOutputToFile()
">> Output dumped into temporary file: <tmp_dir>/<method_name>_<random_number>.txt"
will be
produced before the assertion error is thrown.public void setDumpMismatchedOutputToFile(boolean dumpMismatchedOutputToFile)
">> Output dumped into temporary file: <tmp_dir>/<method_name>_<random_number>.txt"
will be
produced before the assertion error is thrown.dumpMismatchedOutputToFile
- a flag indicating whether the output produced by failing test methods should
be saved into a temporary file.Copyright © 2020 uniVocity Software Pty Ltd. All rights reserved.