7.Android- stress testing, unit testing, log cats use

1. Pressure test monkey

Cmd by entering the following command:

adb shell monkey -p com.example.phonecall --ignore-crashes --ignore-timeouts --monitor-native-crashes -v -v -v 10000 > F:\monkey_log\test1.txt

 

Indicates that the test com.example.phonecall application, sent at random tap / slide / switch event 10000, (-v -v -v) information indicating the logs for the most senior, and then print the information spread F: \ monkey_log \ test1.txt in.

As shown below:

 

2. Unit Testing

2.1 defines a class to be tested MyMath

 

 

2.2 then again defines a unit test class MyMathTest

 

 

2.3 then the test unit to write MyMathTest class test methods, and to measure class MyMath

 

2.4 发现报错does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner in its AndroidManifest.xml

As shown below:

 

 

This is because there is no configuration InstrumentationTestRunner and uses-library file called AndroidManifest.xml.

2.5 Modify AndroidManifest.xml

在application元素上方添加: <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.utilstest"></instrumentation>

在application元素里添加: <uses-library android:name="android.test.runner" />

如下图所示:

 

2.6 再次Run As运行

如下图所示,显示Success则单元测试成功了:

 

 

 

 

 

3.日志猫LogCat使用

日志猫显示标签选项有下面几个:

 

  • verbose: 开发调试过程中一些详细信息,不应该编译进产品中,只在开发阶段使用。
  • debug: 用于调试的信息,编译进产品,但可以在运行时关闭。
  • info: 例如一些运行时的状态信息,这些状态信息在出现问题的时候能提供帮助。
  • warn: 警告系统出现了异常,即将出现错误。
  • error: 系统已经出现了错误。

其中info、warn、Error的警示等级是依次提高,需要一直保留。比如当前选择的是warn(则只显示warn、error)

 

3.1 日志猫如何过滤标签

比如我们过滤出system.out打印(过滤tag信息)的话,则填入:

 

 

这样的话,将会只显示Tag里只带有System.out的信息:

 

 

在安卓中除了用systemOut外,还支持log打印,这样就可以很容易判断出代码的问题类型.

 

3.2 Log打印

在MainActivity.java里写入:

 

 

然后就可以在logcat中看到,我们打印的具体log(log的tag一般填写类名):

 

 

PS:一般我们会将log封装一下,比如下图所示:

 

 

调试的时候,将openLog打开,发布的时候则关闭.

 

Guess you like

Origin www.cnblogs.com/lifexy/p/12150481.html
Recommended