我可以在 Android 设备上使用断言吗? [英] Can I use assert on Android devices?

查看:27
本文介绍了我可以在 Android 设备上使用断言吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用断言 关键字在我的 android 应用程序中在某些情况下在模拟器或我的设备上在测试期间破坏我的应用程序.这可能吗?

I want to use the Assert keyword in my android apps to destroy my app in some cases on the emulator, or my device during testing. Is this possible?

看来模拟器只是忽略了我的断言.

It seems that the emulator just ignores my asserts.

推荐答案

API 提供了 JUnit 断言.

你可以这样做

import static junit.framework.Assert.*;

现在您可以使用junit框架中提供的所有函数,如assertTrue、assertEquals、assertNull.

now you can use all the functions like assertTrue, assertEquals, assertNull that are provided in the junit framework.

注意不要通过eclipse导入Junit4框架,就是org.junit包.您必须使用 junit.framework 包才能使其在 android 设备或模拟器上运行.

Be careful not to import the Junit4 framework through eclipse, that would be the org.junit package. You have to use the junit.framework package to get it working on an android device or the emulator.

这篇关于我可以在 Android 设备上使用断言吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆