LogLogcatRule

public class LogLogcatRule
extends LoggingBaseRule

java.lang.Object
   ↳ org.junit.rules.ExternalResource
     ↳ android.support.test.rule.logging.LoggingBaseRule
       ↳ android.support.test.rule.logging.LogLogcatRule


应用于测试类时,此Rule尝试在执行测试方法之前清除设备上的Logcat缓冲区。 Rule然后在测试方法执行后收集Logcat缓冲区中的所有内容,并将其记录到外部存储器上的文件中。 默认文件位置保持在getTestDir(String, String, int) TestRule通过调用设备的logcat命令来执行这些操作。

Test methods can perform additional clearing and capturing of the Logcat buffer through the clearLogcat() and dumpLogcat(String) methods.

Usage: \@Rule public LogLogcatRule mLogLogcatRule = new LogLogcatRule();

Summary

Public constructors

LogLogcatRule()

LogLogcatRule(File logFileOutputDirectory, String fileName)

Public methods

void afterTest()

测试运行后,将logcat缓冲区提取到文件。

void beforeTest()

测试运行前清除logcat缓冲区。

static void clearLogcat()

清除当前的logcat缓冲区。

File dumpLogcat(String logFileName)

将logcat缓冲区的当前状态转储到测试方法的日志记录目录中的文件。

String getDefaultLogFileName()

返回此规则类的默认日志文件名称。

Inherited methods

From class android.support.test.rule.logging.LoggingBaseRule
From class org.junit.rules.ExternalResource
From class java.lang.Object
From interface org.junit.rules.TestRule

Public constructors

LogLogcatRule

LogLogcatRule ()

LogLogcatRule

LogLogcatRule (File logFileOutputDirectory, 
                String fileName)

Parameters
logFileOutputDirectory File
fileName String

Public methods

afterTest

void afterTest ()

测试运行后,将logcat缓冲区提取到文件。

beforeTest

void beforeTest ()

测试运行前清除logcat缓冲区。

clearLogcat

void clearLogcat ()

清除当前的logcat缓冲区。 这可以从测试方法代码中调用,但是会在测试方法结束时改变Rule缓冲区最终日志的结果。

dumpLogcat

File dumpLogcat (String logFileName)

将logcat缓冲区的当前状态转储到测试方法的日志记录目录中的文件。 在编写测试以在不同时间点记录logcat时,可以使用此方法。

Parameters
logFileName String: where Logcat output is sent
Returns
File the File where output was logged

getDefaultLogFileName

String getDefaultLogFileName ()

返回此规则类的默认日志文件名称。 空返回值表示规则不会记录到文件。

Returns
String