我想测试'Crittercism'工具,我怎么能为android开发一个崩溃的应用程序?

时间:2013-12-16 07:25:19

标签: android crash crittercism

我想为Android开发一个基本应用程序,它必须随机崩溃以测试'crittercism'工具。我该怎么办才能让应用程序崩溃?

感谢。

2 个答案:

答案 0 :(得分:2)

将某些内容设置为null并尝试使用它,例如:

TextView v;
v.setText("X");

答案 1 :(得分:0)

在SO上关于这一点的问题很少,而且大多数答案都提出了创造性的方法来做违法行为以触发异常。我认为它们不实用,特别是如果你想测试不同类型的例外。

正确的方法是:

throw new RuntimeException("some message");

或特定的:

throw new IllegalStateException("some message");
throw new NullPointerException("some message");
throw new ArrayIndexOutOfBoundsException("some message");
throw new ClassCastException("some message");
...

请参阅:https://developer.android.com/reference/java/lang/RuntimeException.html

您可以对任何checked type异常执行相同操作以测试异常处理(try / catch)。