You have only one test in your class (testPlayMyMusic()), why are you expecting results from two ? "OK (1 test)" means your test succeeded.
On Mar 11, 10:28 am, perrot <linca30...@gmail.com> wrote: > Hi, > > I am writing a Instrumnetation using the > AvtivityInstrumnetationTestCase class and a test case about play > music. When I execute the test case, it is work fine. But there the > problem is the application play nothing. The Activity appear one > moment then back to HOME screen. > > Reference my code: > File: MainActivity.java > > ----------------------------------------------------------------- > package com.android.testapp; > > import android.app.Activity; > import android.content.Context; > import android.content.Intent; > > import android.os.Bundle; > import android.util.Log; > import android.media.AudioManager; > import android.media.MediaPlayer; > import android.media.MediaPlayer.OnCompletionListener; > > public class MainActivity extends Activity { > > /** Called when the activity is first created. */ > > @Override > > public void onCreate(Bundle savedInstanceState) { > > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > } > > public void PlayMyMusic(){ > //----Pre set---- > AudioManager am=(AudioManager) > getApplicationContext().getSystemService(AUDIO_SERVICE); > try { > //Utility.PlayMusic("/storage/sample.mp3"); > > MediaPlayer mp = new MediaPlayer(); > Log.e("debug","media player set data source..."); > mp.setDataSource("/storage/sample.mp3"); > Log.e("debug","media player set loop..."); > mp.setLooping(true); > > Log.e("debug","media player prepare..."); > mp.prepare(); > Log.e("debug","media player start..."); > mp.start(); > Log.e("debug","media player started..."); > // i.e. react on the end of the music-file: > mp.setOnCompletionListener(new OnCompletionListener(){ > > // @Override > public void onCompletion(MediaPlayer arg0) { > // File has ended !!! > } > }); > } catch (Exception e) { > Log.e("debug","media player error..."+e.toString()); > // TODO Auto-generated catch block > e.printStackTrace(); > } > > } > > File:PlayMyMusic.java > ----------------------------------------------------------------- > package test; > > import com.android.testapp.MainActivity; > import android.test.ActivityInstrumentationTestCase2; > import android.test.suitebuilder.annotation.MediumTest; > > public class PlayMyMusic extends > ActivityInstrumentationTestCase2<MainActivity> { > > public PlayMyMusic() { > > super("com.android.testapp", MainActivity.class); > > } > > public PlayMyMusic(String pkg, Class<MainActivity> activityClass) { > > super(pkg, activityClass); > > } > > @MediumTest > > public void testPlayMyMusic() throws Exception { > > getActivity().PlayMyMusic(); > > } > > } > > File:TestApp.Manifest > ----------------------------------------------------------------- > <?xml version="1.0" encoding="utf-8"?> > <manifest xmlns:android="http://schemas.android.com/apk/res/android" > package="com.android.testapp" android:versionCode="1" > android:versionName="1.0"> > <application android:icon="@drawable/icon" android:label="@string/ > app_name"> > <activity android:name=".MainActivity" android:label="@string/ > app_name"> > <intent-filter> > <action > android:name="android.intent.action.MAIN" /> > <category > android:name="android.intent.category.LAUNCHER" /> > </intent-filter> > </activity> > > <uses-library android:name="android.test.runner" /> > </application> > > <instrumentation android:targetPackage="com.android.testapp" > android:name="android.test.InstrumentationTestRunner" > android:label="Test Unit Tests"></instrumentation> > > <uses-permission android:name="android.permission.WRITE_SETTINGS"></ > uses-permission> > <uses-permission android:name="android.permission.INJECT_EVENT"></ > uses-permission> > > <uses-permission android:name="android.permission.RESTART_PACKAGES"></ > uses-permission> > </manifest> > ----------------------------------------------------------------- > > Type below command to run it.>adb shell am instrument -e class > test.PlayMyMusic -w com.android.testapp/android.test.InstrumentationTestRunner > > ----------------------------------------------------------------- > Command logcat to get the log>adb logcat debug:E *:S > > E/debug (15281): media player set data source... > E/debug (15281): media player set loop... > E/debug (15281): media player prepare... > E/debug (15281): media player start... > E/debug (15281): media player started... > > ----------------------------------------------------------------- > I get the output "OK (1 test)". This is so curious. Normally if it is > a pass test, I will get the output "OK (2 test)". > test.PlayMyMusic:. > Test results for InstrumentationTestRunner=. > Time: 3.625 > > OK (1 test) > > Help me, > Perrot -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en