|
根据测试概念分为:
黑盒测试:测试人员不知道源代码的情况下,根据软件的输入输出进行测试
白盒测试:测试人员知道源代码的情况下,根据源代码的逻辑进行测试是白盒测试
根据测试的粒度分为:
单元测试junit test
集成测试intergration test
系统测试 system test
根据测试地程度分为:
压力测试 (pressure test)
冒烟测试 (smoke test)
Monkey猴子
代码:
1.被测试类:
- public class MethodActivity {
- //相加的方法
- public int add(int i, int j) {
- int sum = i+j;
- return sum;
- }
- }
复制代码 2.测试类:
可以在已有的androidTest目录下创建,也可以自己新建一个包
注意事项:
1)向测试框架抛出异常
2)不可以使用成员变量
3)在测试类中方法需要用public修饰,方法名是test+所要测试的方法
- public class TestMethodActivity extends AndroidTestCase {
- public void testAdd()throws Exception {
- MethodActivity ma = new MethodActivity();
- int result = ma.add(3, 5);
- assertEquals(8, result);
- }
- }
复制代码- 3.在 AndroidManifest.xml 中添加指令集 instrumentation 和测试库 uses-library
- [html] view plain copy
- <!--在application节点外添加测试的指令集 -->
- <instrumentation android:name="android.test.InstrumentationTestRunner
- android:targetPackage="com.test.junit"></instrumentation>
- <!--在application节点内测试需要的jar包-->
- <uses-library android:name="android.test.runner"/>
复制代码 4.在目录视图中找到TestStudentActivity右键点击Create‘TestStudentActivity
5.运行代码
6.红线代表测试不通过,绿线代表测试通过
|
|