ILogSaverListener

public interface ILogSaverListener
implements ITestInvocationListener

com.android.tradefed.result.ILogSaverListener


允许 ITestInvocationListener 监听日志文件何时保存。

这样一来,多个 ITestInvocationListener 在生成报告时可以使用同一已保存的日志文件,并且避免了在调用 ITestLogger.testLog(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource) 时让每个监听器单独保存文件。

实现此接口的类应注意,每当调用 ITestLogger.testLog(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource) 时,系统都会调用 testLogSaved(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource, com.android.tradefed.result.LogFile)

此类还会传递全局 ILogSaver 实例,以便 ITestInvocationListener 可以将其他文件保存到同一位置。

摘要

公共方法

default void logAssociation(String dataName, LogFile logFile)

在某些情况下,日志必须与测试用例紧密关联,但无法在直接 testLogSaved(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource, com.android.tradefed.result.LogFile) 回调中实现此目的。

default void setLogSaver(ILogSaver logSaver)

ILogSaver 设置为允许实现者保存文件。

default void testLogSaved(String dataName, LogDataType dataType, InputStreamSource dataStream, LogFile logFile)

在保存测试日志时调用。

公共方法

logAssociation

public void logAssociation (String dataName, 
                LogFile logFile)

在某些情况下,日志必须与测试用例紧密关联,但无法在直接 testLogSaved(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource, com.android.tradefed.result.LogFile) 回调中实现这一点。因此,此回调允许明确提供强关联。

参数
dataName String:数据的名称

logFile LogFile:之前记录的 LogFile,应与测试用例相关联。

setLogSaver

public void setLogSaver (ILogSaver logSaver)

ILogSaver 设置为允许实现者保存文件。

参数
logSaver ILogSaverILogSaver

testLogSaved

public void testLogSaved (String dataName, 
                LogDataType dataType, 
                InputStreamSource dataStream, 
                LogFile logFile)

在保存测试日志时调用。

应取代 ITestInvocationListener.testLog(String, LogDataType, InputStreamSource) 使用。

参数
dataName String:数据的描述性名称。例如“device_logcat”。String请注意,dataName 在每次调用时可能不是唯一的。也就是说,实现者必须能够处理具有相同 dataName 的多次调用

dataType LogDataType:数据的 LogDataType

dataStream InputStreamSource:数据的 InputStreamSource。实现人员应调用 createInputStream 开始读取数据,并确保在完成后关闭生成的 InputStream。

logFile LogFile:包含已保存文件的元数据的 LogFile