Classes:from parent to child

1.

junit


packagejunit.framework;<br><br>publicinterfaceTest {    publicabstractint countTestCases();    publicabstractvoid run(TestResult result);}

?

Assert

package junit.framework;
public class Assert {
...
assertTrue()
assertFalse()
fail()
assertEquals()
assertNotNull()
assertNull()
...
}
复制代码

fail will throw error, other's function will call fail in the end.

2. TestCase

package junit.framework;
public
abstract class TestCase extends Assert implements Test {

protected void runTest() throws Throwable {
assertNotNull(fName);
Method runMethod= null;
try {
// use getMethod to get all public inherited
// methods. getDeclaredMethods returns all
// methods of this class but excludes the
// inherited ones.
runMethod= getClass().getMethod(fName, (Class[]) null);
} catch (NoSuchMethodException e) {
fail("Method \""+fName+"\" not found");
}
try {
runMethod.invoke(this, (Object[]) null);
}
     ....
}
public String getName() {
return fName;
}
public void setName(String name) {
fName= name;
}
protected void setUp() throws Exception {
}

protected void tearDown() throws Exception {
}
....

复制代码

TestCase has a method run(), which use java reflect to get the "Class" and "Method"

then call method.invoke() to start method.

3.InstrumentationTestCase

package android.test;
public class InstrumentationTestCase extends TestCase {
....
public final <T extends Activity> T launchActivity(
String pkg,
Class<T> activityCls,
Bundle extras) {
Intent intent = new Intent(Intent.ACTION_MAIN);
if (extras != null) {
intent.putExtras(extras);
}
return launchActivityWithIntent(pkg, activityCls, intent);
}
...
public void runTestOnUiThread(final Runnable r) throws Throwable {
  ....
}
...
protected void runTest() throws Throwable {
  ...
}

private void runMethod(Method runMethod, int tolerance) throws Throwable {
runMethod(runMethod, tolerance, false);
}
复制代码

更多相关文章

  1. Android(Java):jni源代码
  2. Android重启应用程序代码
  3. Android实现手机定位的案例代码
  4. Android写文件到SDCard的简单代码
  5. Android手电筒小程序实现代码
  6. Android中通过代码检测系统是否有root权限
  7. Android 代码片段---获取手机通讯录列表

随机推荐

  1. sqlserver分页查询处理方法小结
  2. SqlServer索引的原理与应用详解
  3. SQL Server 2012使用Offset/Fetch Next实
  4. 大容量csv快速内导入sqlserver的解决方法
  5. SQL查询字段被包含语句
  6. Sql Server2012 使用IP地址登录服务器的
  7. SQLServer查询某个时间段购买过商品的所
  8. SQL Server学习笔记之事务、锁定、阻塞、
  9. 分享一个简单的sql注入
  10. SQL Server 性能调优之查询从20秒至2秒的