Android 中Junit 测试框架(单元测试)

来源:互联网 发布:iphone垃圾清理软件 编辑:程序博客网 时间:2024/05/18 02:48

第一步:首先在AndroidManifest.xml中加入下面的代码

在application 节点下加入如下代码:

<uses-library android:name="android.test.runner" />

在manifest 节点下加入如下代码:

<instrumentation android:name="android.test.InstrumentationTestRunner"

<!--应用的包名-->

  android:targetPackage="lwp.test.action"  

  android:label="Tests My App" />

第二步:编写单元测试代码(选择要测试的方法,右键点击“Run As”--“Android Junit Test” ):

import android.test.AndroidTestCase;
import android.util.Log;
public class XMLTest extends AndroidTestCase {
public void testSomething() throws Throwable {
Assert.assertTrue(1 + 1 == 3);
}
}


0 0
原创粉丝点击