两种方法:
1. 建立一个test case。
右键当前object,new一个junit test case, 填写包名,类名,点击finish即可。
然后我们需要在manifest.xml文件中进行配置,在application外面配置
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="myTestlabel"
android:targetPackage="com.androidstudydemo.common" />
targetPackage与<manifest>标签的package设置相同
在application里面添加一句<uses-library android:name="android.test.runner" />
打开刚生产的类,可以看见该类继承了extends TestCase,然后我们就可以在里面写单元测试的方法了。
2.建立一个test object.
右键当前object,new一个junit test object,会创建一个与当前object目录结构差不多的工程。