RuleLoggingUtils

public class RuleLoggingUtils
extends Object

java.lang.Object
   ↳ android.support.test.rule.logging.RuleLoggingUtils


确保日志记录规则以相同方式执行某些操作的便捷方法。

Summary

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运行时兼容的进程在系统上启动 Process

static Process startProcess(String[] commandParts)

Process指定的命令和参数启动 commandParts

static void startProcessAndLogToFile(String[] commandParts, File logFile, int androidVersion)

根据传入的Android版本号,使用 startCmdAndLogOutputPostL(String[], File)startProcessAndWriteOutputToFilePreL(String[], File)在系统上启动 Process

static void startProcessAndWriteOutputToFilePreL(String[] commandParts, File logFile)

使用与所有Android运行时兼容的进程在系统上启动 Process

static void writeErrorToFileAndLogcat(File file, String logTag, String errorMessage, Exception exception)

用于将错误消息写入文件并将logcat写入错误的实用程序方法。

static void writeProcessOutputToFile(Process process, File logFile)

实用程序方法读取 Process的输出并将其写入文件。

Inherited methods

From class java.lang.Object

Constants

LOGGING_SUB_DIR_NAME

String LOGGING_SUB_DIR_NAME

常量值:“testdata”

Public constructors

RuleLoggingUtils

RuleLoggingUtils ()

Public methods

assertEmptyFile

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

assertFileContentContains

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

assertFileContentDoesNotContain

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

assertFileContentStartsWith

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

getTestDir

File getTestDir (String className, 
                String testName, 
                int testRunNumber)

检索应该写入日志规则日志的目录。 此目录位于外部存储器上,因此在卸载应用程序时不会被删除。 这允许尽管致命(认为OutOfMemory)异常,仍可检索文件。 只要在单次测试运行中运行多次测试方法以指示日志记录的迭代次数, testRunNumber应该设置testRunNumber 使用零作为默认值。

Parameters
className String
testName String
testRunNumber int
Returns
File

getTestFile

File getTestFile (String className, 
                String testName, 
                String filename, 
                int testRunNumber)

检索应该写入测试的测试目录内的文件句柄。

Parameters
className String
testName String
filename String
testRunNumber int
Returns
File

getTestRunDir

File getTestRunDir ()

检索应写入测试的测试运行目录。

Returns
File

getTestRunFile

File getTestRunFile (String filename)

在可以写测试数据的测试目录中检索文件句柄以进行完整的测试运行。

Parameters
filename String
Returns
File

printFileToLogcat

void printFileToLogcat (File logFile, 
                String logcatTag)

为了调试目的,将文件打印到logcat的实用方法。

Parameters
logFile File
logcatTag String
Throws
IOException

startCmdAndLogOutputPostL

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

startProcess

Process startProcess (String[] commandParts)

Process指定的命令和参数启动 commandParts

您必须在返回的对象上调用 Process.destroy()

Parameters
commandParts String
Returns
Process
Throws
IOException

startProcessAndLogToFile

void startProcessAndLogToFile (String[] commandParts, 
                File logFile, 
                int androidVersion)

根据传入的Android版本号,使用 startCmdAndLogOutputPostL(String[], File)startProcessAndWriteOutputToFilePreL(String[], File)在系统上启动 Process

This utility method eliminates the need to grant your app some system permissions when running on Android Lollipop or above by using the test instrumentation to run the specified command. If you are testing on pre-Lollipop devices you will need to ensure your test APK has been granted any permissions needed to execute the commands 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.

startProcessAndWriteOutputToFilePreL

void startProcessAndWriteOutputToFilePreL (String[] commandParts, 
                File logFile)

使用与所有Android运行时兼容的进程在系统上启动Process 标准和错误输出被重定向到指定的文件。

This command runs as the current user and requires appropriate permissions be granted to the App/Test APK. If the runtime is Android M or greater use 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

writeErrorToFileAndLogcat

void writeErrorToFileAndLogcat (File file, 
                String logTag, 
                String errorMessage, 
                Exception exception)

用于将错误消息写入文件并将logcat写入错误的实用程序方法。

Parameters
file File
logTag String
errorMessage String
exception 异常

writeProcessOutputToFile

void writeProcessOutputToFile (Process process, 
                File logFile)

实用程序方法读取 Process的输出并将其写入文件。

Parameters
process Process
logFile File
Throws
IOException