发布于 2016-03-07 10:37:30 | 140 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了Android中使用AndroidTestCase的方法实例,本文直接给出实现代码,需要的朋友可以参考下

Android 使用 AndroidTestCase 的步骤
1.新建一个类继承 AndroidTestCase



public class TestAudio extends AndroidTestCase {  

    private AudioManager mAudioManager;  

    private boolean mUseFixedVolume;  

    private final static long TIME_TO_PLAY = 2000;  

    private final static int MP3_TO_PLAY = R.raw.testmp3;  

      

    @Override  

    protected void setUp() throws Exception {  

        // TODO Auto-generated method stub  

        super.setUp();  

          

    }  

      

    public void testmp3(){  

        MediaPlayer mp = MediaPlayer.create(mContext, MP3_TO_PLAY);  

        mp.setAudioStreamType(STREAM_MUSIC);  

        mp.setLooping(true);  

        mp.start();  

        try {  

            Thread.sleep(20*1000);  

        } catch (InterruptedException e) {  

            // TODO Auto-generated catch block  

            e.printStackTrace();  

        }  

    }  

}  


2.修改 AndroidManifest.xml 文件
在application 内部添加


<uses-library android:name="android.test.runner" />


application标签同级的位置添加


<instrumentation

        android:name="android.test.InstrumentationTestRunner"

        android:label="test"

        android:targetPackage="com.example.testaudio" />


上面的2个标签的位置很重要,我就是把instrumentation 的位置发错了才会郁闷了的.
具体:


<manifest xmlns:android="http://schemas.android.com/apk/res/android"  

    package="com.example.testaudio"  

    android:versionCode="1"  

    android:versionName="1.0" >  

  

    <uses-sdk  

        android:minSdkVersion="8"  

        android:targetSdkVersion="18" />  

  

    <application  

        android:allowBackup="true"  

        android:icon="@drawable/ic_launcher"  

        android:label="@string/app_name"  

        android:theme="@style/AppTheme" >  

        <uses-library android:name="android.test.runner" />  

    </application>  

    <!-- 与application标签同级的位置添加 -->  

    <instrumentation  

        android:name="android.test.InstrumentationTestRunner"  

        android:label="test"  

        android:targetPackage="com.example.testaudio" />  

  

</manifest>  



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务