public class RuleLoggingUtils
extends Object
java.lang.Object | |
↳ | android.support.test.rule.logging.RuleLoggingUtils |
确保日志记录规则以相同方式执行某些操作的便捷方法。
Constants |
|
---|---|
String |
LOGGING_SUB_DIR_NAME |
Public constructors |
|
---|---|
RuleLoggingUtils() |
Public methods |
|
---|---|
static void |
assertEmptyFile(String message, File file) 测试实用程序方法来检查文件是否为空。 |
static void |
assertFileContentContains(String message, File file, String contentString) 测试实用程序方法来检查文件是否包含指定的内容。 |
static void |
assertFileContentDoesNotContain(String message, File file, String contentString) 测试实用程序方法来检查文件是否不包含指定的内容。 |
static void |
assertFileContentStartsWith(String message, File file, String contentString) 测试实用程序方法可快速检查文件是否以指定的内容开始。 |
static File |
getTestDir(String className, String testName, int testRunNumber) 检索应该写入日志规则日志的目录。 |
static File |
getTestFile(String className, String testName, String filename, int testRunNumber) 检索应该写入测试的测试目录内的文件句柄。 |
static File |
getTestRunDir() 检索应写入测试的测试运行目录。 |
static File |
getTestRunFile(String filename) 在可以写测试数据的测试目录中检索文件句柄以进行完整的测试运行。 |
static void |
printFileToLogcat(File logFile, String logcatTag) 为了调试目的,将文件打印到logcat的实用方法。 |
static void |
startCmdAndLogOutputPostL(String[] commandParts, File logFile) 使用与所有Android运行时兼容的进程在系统上启动 |
static Process |
startProcess(String[] commandParts) 用 |
static void |
startProcessAndLogToFile(String[] commandParts, File logFile, int androidVersion) 根据传入的Android版本号,使用 |
static void |
startProcessAndWriteOutputToFilePreL(String[] commandParts, File logFile) 使用与所有Android运行时兼容的进程在系统上启动 |
static void |
writeErrorToFileAndLogcat(File file, String logTag, String errorMessage, Exception exception) 用于将错误消息写入文件并将logcat写入错误的实用程序方法。 |
static void |
writeProcessOutputToFile(Process process, File logFile) 实用程序方法读取 |
Inherited methods |
|
---|---|
![]() java.lang.Object
|
String LOGGING_SUB_DIR_NAME
常量值:“testdata”
RuleLoggingUtils ()
void assertEmptyFile (String message, File file)
测试实用程序方法来检查文件是否为空。
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)
测试实用程序方法来检查文件是否包含指定的内容。
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)
测试实用程序方法来检查文件是否不包含指定的内容。
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)
测试实用程序方法可快速检查文件是否以指定的内容开始。
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)
检索应该写入日志规则日志的目录。 此目录位于外部存储器上,因此在卸载应用程序时不会被删除。 这允许尽管致命(认为OutOfMemory)异常,仍可检索文件。 只要在单次测试运行中运行多次测试方法以指示日志记录的迭代次数, testRunNumber
应该设置testRunNumber
。 使用零作为默认值。
Parameters | |
---|---|
className |
String
|
testName |
String
|
testRunNumber |
int
|
Returns | |
---|---|
File |
File getTestFile (String className, String testName, String filename, int testRunNumber)
检索应该写入测试的测试目录内的文件句柄。
Parameters | |
---|---|
className |
String
|
testName |
String
|
filename |
String
|
testRunNumber |
int
|
Returns | |
---|---|
File |
File getTestRunDir ()
检索应写入测试的测试运行目录。
Returns | |
---|---|
File |
File getTestRunFile (String filename)
在可以写测试数据的测试目录中检索文件句柄以进行完整的测试运行。
Parameters | |
---|---|
filename |
String
|
Returns | |
---|---|
File |
void printFileToLogcat (File logFile, String logcatTag)
为了调试目的,将文件打印到logcat的实用方法。
Parameters | |
---|---|
logFile |
File
|
logcatTag |
String
|
Throws | |
---|---|
IOException |
void startCmdAndLogOutputPostL (String[] commandParts, File logFile)
使用与所有Android运行时兼容的进程在系统上启动Process
。 标准和错误输出被重定向到指定的文件。
此命令在测试工具内运行,并且已授予一些开发权限。
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)
用 Process
指定的命令和参数启动 commandParts
。
您必须在返回的对象上调用 Process.destroy()
。
Parameters | |
---|---|
commandParts |
String
|
Returns | |
---|---|
Process |
Throws | |
---|---|
IOException |
void startProcessAndLogToFile (String[] commandParts, File logFile, int androidVersion)
根据传入的Android版本号,使用 startCmdAndLogOutputPostL(String[], File)
或 startProcessAndWriteOutputToFilePreL(String[], File)
在系统上启动 Process
。
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)
使用与所有Android运行时兼容的进程在系统上启动Process
。 标准和错误输出被重定向到指定的文件。
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)
用于将错误消息写入文件并将logcat写入错误的实用程序方法。
Parameters | |
---|---|
file |
File
|
logTag |
String
|
errorMessage |
String
|
exception |
异常
|
void writeProcessOutputToFile (Process process, File logFile)
实用程序方法读取 Process
的输出并将其写入文件。
Parameters | |
---|---|
process |
Process
|
logFile |
File
|
Throws | |
---|---|
IOException |