android cts and junit
16lz
2021-01-23
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);
}
更多相关文章
- Android(Java):jni源代码
- Android重启应用程序代码
- Android实现手机定位的案例代码
- Android写文件到SDCard的简单代码
- Android手电筒小程序实现代码
- Android中通过代码检测系统是否有root权限
- Android 代码片段---获取手机通讯录列表