public
class
RuleLoggingUtils
extends Object
java.lang.Object | |
↳ | android.support.test.rule.logging.RuleLoggingUtils |
Convenience methods to ensure logging rules perform certain actions in the same manner.
Constants | |
---|---|
String |
LOGGING_SUB_DIR_NAME
|
Public constructors | |
---|---|
RuleLoggingUtils()
|
Public methods | |
---|---|
static
void
|
assertEmptyFile(String message, File file)
Test utility method to check if a file is empty. |
static
void
|
assertFileContentContains(String message, File file, String contentString)
Test utility method to check if a file contains the specified content. |
static
void
|
assertFileContentDoesNotContain(String message, File file, String contentString)
Test utility method to check if a file doesn't contain the specified content. |
static
void
|
assertFileContentStartsWith(String message, File file, String contentString)
Test utility method to quickly check if a file begins with the specified content. |
static
File
|
getTestDir(String className, String testName, int testRunNumber)
Retrieve the directory where logging rules logs should be written to. |
static
File
|
getTestFile(String className, String testName, String filename, int testRunNumber)
Retrieve a file handle that is within the testing directory where tests should be written to. |
static
File
|
getTestRunDir()
Retrieve the test run directory where tests should be written to. |
static
File
|
getTestRunFile(String filename)
Retrieve a file handle within the testing directory where test data can be written for the complete test run. |
static
void
|
printFileToLogcat(File logFile, String logcatTag)
Utility method to print file to logcat for debugging purposes. |
static
void
|
startCmdAndLogOutputPostL(String[] commandParts, File logFile)
Start a |
static
Process
|
startProcess(String[] commandParts)
Start a |
static
void
|
startProcessAndLogToFile(String[] commandParts, File logFile, int androidVersion)
Start a |
static
void
|
startProcessAndWriteOutputToFilePreL(String[] commandParts, File logFile)
Start a |
static
void
|
writeErrorToFileAndLogcat(File file, String logTag, String errorMessage, Exception exception)
Utility method to write an error message to a file and logcat as an error. |
static
void
|
writeProcessOutputToFile(Process process, File logFile)
Utility method to read a |
Inherited methods | |
---|---|
![]()
java.lang.Object
|
String LOGGING_SUB_DIR_NAME
Constant Value: "testdata"
RuleLoggingUtils ()
void assertEmptyFile (String message, File file)
Test utility method to check if a file is empty.
Parameters | |
---|---|
message |
String :
to be used when throwing an Assertion error if the content is not empty |
file |
File :
to inspect |
Throws | |
---|---|
AssertionError |
is thrown when the file isn't empty |
IOException |
when the there are issues accessing the file parameter
|
void assertFileContentContains (String message, File file, String contentString)
Test utility method to check if a file contains the specified content.
Parameters | |
---|---|
message |
String :
to be used when throwing an Assertion error if the content does not
match |
file |
File :
to inspect |
contentString |
String :
to compare against the content of the file |
Throws | |
---|---|
AssertionError |
is thrown when the content is not found |
IOException |
when the there are issues accessing the file parameter
|
void assertFileContentDoesNotContain (String message, File file, String contentString)
Test utility method to check if a file doesn't contain the specified content.
Parameters | |
---|---|
message |
String :
to be used when throwing an Assertion error if the content does not
match |
file |
File :
to inspect |
contentString |
String :
to compare against the content of the file |
Throws | |
---|---|
AssertionError |
is thrown when the content is not found |
IOException |
when the there are issues accessing the file parameter
|
void assertFileContentStartsWith (String message, File file, String contentString)
Test utility method to quickly check if a file begins with the specified content.
Parameters | |
---|---|
message |
String :
to be used if the content does not match |
file |
File :
to inspect |
contentString |
String :
to compare against the content of the file |
Throws | |
---|---|
AssertionError |
is thrown when the content is not found |
IOException |
when the there are issues accessing the file parameter
|
File getTestDir (String className, String testName, int testRunNumber)
Retrieve the directory where logging rules logs should be written to.
This directory is on external storage so it is not removed when the app is uninstalled. This
allows the files to be retrieved despite fatal (think OutOfMemory) exceptions.
testRunNumber
should be set whenever a test method is run more than one time in a
single test run to indicate which iteration the logging is for. Use zero as a default.
Parameters | |
---|---|
className |
String
|
testName |
String
|
testRunNumber |
int
|
Returns | |
---|---|
File |
File getTestFile (String className, String testName, String filename, int testRunNumber)
Retrieve a file handle that is within the testing directory where tests should be written to.
Parameters | |
---|---|
className |
String
|
testName |
String
|
filename |
String
|
testRunNumber |
int
|
Returns | |
---|---|
File |
File getTestRunDir ()
Retrieve the test run directory where tests should be written to.
Returns | |
---|---|
File |
File getTestRunFile (String filename)
Retrieve a file handle within the testing directory where test data can be written for the complete test run.
Parameters | |
---|---|
filename |
String
|
Returns | |
---|---|
File |
void printFileToLogcat (File logFile, String logcatTag)
Utility method to print file to logcat for debugging purposes.
Parameters | |
---|---|
logFile |
File
|
logcatTag |
String
|
Throws | |
---|---|
IOException |
void startCmdAndLogOutputPostL (String[] commandParts, File logFile)
Start a Process
on the system using a process compatible with all Android runtimes.
Standard and error output is redirected to the specified file.
This command runs within the testing instrumentation and has some development permissions already granted.
Parameters | |
---|---|
commandParts |
String :
the command and parameters to execute on the system |
logFile |
File :
where comamnd output is written, or in the case of an error, the
exception output is written
|
Process startProcess (String[] commandParts)
Start a Process
with the command and arguments specified in commandParts
.
You must call Process.destroy()
on the object returned.
Parameters | |
---|---|
commandParts |
String
|
Returns | |
---|---|
Process |
Throws | |
---|---|
IOException |
void startProcessAndLogToFile (String[] commandParts, File logFile, int androidVersion)
Start a Process
on the system using either
startCmdAndLogOutputPostL(String[], File)
or
startProcessAndWriteOutputToFilePreL(String[], File)
according to the Android
version number passed in.
Parameters | |
---|---|
commandParts |
String :
the command and parameters to execute on the system |
logFile |
File :
where comamnd output is written, or in the case of an error, where the
exception output is written |
androidVersion |
int :
overrides the system Android version which is used to decide the best
method to invoke the command with. This is useful for code that needs
to write Android version specific tests.
|
void startProcessAndWriteOutputToFilePreL (String[] commandParts, File logFile)
Start a Process
on the system using a process compatible with all Android runtimes.
Standard and error output is redirected to the specified file.
startCmdAndLogOutputPostL(String[], File)
instead to run as with instrumentation
permissions.
Parameters | |
---|---|
commandParts |
String :
the command and parameters to execute on the system |
logFile |
File :
where comamnd output is written, or in the case of an error, the
exception output is written
|
void writeErrorToFileAndLogcat (File file, String logTag, String errorMessage, Exception exception)
Utility method to write an error message to a file and logcat as an error.
Parameters | |
---|---|
file |
File
|
logTag |
String
|
errorMessage |
String
|
exception |
Exception
|
void writeProcessOutputToFile (Process process, File logFile)
Utility method to read a Process
's output and write it to a file.
Parameters | |
---|---|
process |
Process
|
logFile |
File
|
Throws | |
---|---|
IOException |