android cts and junit
2012-04-03 22:01
106 查看
Classes:from parent to child
1.
junit
Assert
fail will throw error, other's function will call fail in the end.
2. TestCase
TestCase has a method run(), which use java reflect to get the "Class" and "Method"
then call method.invoke() to start method.
3.InstrumentationTestCase
1.
junit
package junit.framework; public interface Test { public abstract int countTestCases(); public abstract void 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 cts and junit
- testBatchAndFlush(android.hardware.cts.SensorTest): WaitForFlush | sensor='PROXIMITY'
- Junit and android test
- Android-Junit-Report测试报告生成——Android自动化测试学习历程
- Android USB Connections Explained: MTP, PTP, and USB Mass Storage
- android_开发_EditText_and_TextView属性
- Android Tasks and Back Stack (一)
- Android最详细的Alibaba-AndFix 热修复框架的使用
- 【Android 官方文档】翻译Android官方文档 Processes and Threads(五)
- android之Activity的Tasks and Back Stack
- Android的安全性和权限(Security and Permission)(一)
- android Makefile and main.mk
- unable to find attribute android:fontVariationSettings and android:ttcIndex
- 转: Android 电源管理专题之监测电池电量和充电状态Monitoring the Battery Level and Charging State
- 【android,2】2.安卓的junit测试
- Android 快速开发框架:推荐10个框架:afinal、ThinkAndroid、andBase、KJFrameForAndroid、SmartAndroid、dhroid..
- Multiple strings.xml files cause order and incomplete problems in android
- Android--Fix plugin version and sync project
- Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.
- On Memory Leaks in Java and in Android.