Android JUnit 测试不显示测试栏(Eclipse)

发布于 2024-10-30 00:55:06 字数 3985 浏览 3 评论 0原文

我是 Android 开发应用程序的新手,尝试使用 JUnit 测试框架通过 ActivityInstrumentationTestCase2 类来测试下面的代码,并进行有关 Android 文档中的测试基础知识。但是当测试运行时,我没有得到任何有关测试的信息(Eclipse 中的 JUnit 界面中的红色、绿色、蓝色条)(事实上,我相信测试没有发生,即使控制台说是)。

以下是 JUnit 代码和清单文件:

package gml.android.mixdroid.test;
import java.util.ArrayList;
import gml.android.mixdroid.SeekbarActivity;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.SeekBar;
import android.widget.TextView;

public class SeekBarActivityTest extends ActivityInstrumentationTestCase2<SeekbarActivity> {

private SeekbarActivity mActivity;
private ArrayList<SeekBar> mSeekBars;
private ArrayList<TextView> mProgress;
private ArrayList<TextView> mTracks;

public SeekBarActivityTest(String pkg, Class<SeekbarActivity> activityClass) {
    super("gml.android.mixdroid", SeekbarActivity.class);
}

public void setUp() throws Exception{
     super.setUp();
     mActivity = getActivity();
     mSeekBars = mActivity.getSeekBars();
     mProgress = mActivity.getProgressTextViews();
     mTracks = mActivity.getTrackingTextViews();

}

public void testPreconditions(){
    assertNotNull(mSeekBars);
    assertNotNull(mProgress);
    assertNotNull(mTracks);
    for(SeekBar s : mSeekBars){
        assertNotNull(s);
    }
    for(TextView p : mProgress){
        assertNotNull(p);
    }
    for(TextView t : mTracks){
        assertNotNull(t);
    }
}

public void testInitSeekBars() {
    assertEquals(SeekbarActivity.NUMBER_OF_SEEK_BARS, mSeekBars.size());
}

public void testInitTextViews() {
    assertEquals(SeekbarActivity.NUMBER_OF_SEEK_BARS, mTracks.size());
    assertEquals(SeekbarActivity.NUMBER_OF_SEEK_BARS, mProgress.size());
}
}

Manifest (Activity):

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="gml.android.mixdroid"
  android:versionCode="1"
  android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".SeekbarActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>
<uses-sdk android:minSdkVersion="7" />

</manifest> 

Manifest( JUnit):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  android:versionCode="1"
  android:versionName="1.0" 
  package="gml.android.mixdroid.test">
<application 
    android:icon="@drawable/icon"
     android:label="@string/app_name">
     <uses-library android:name="android.test.runner" />
</application>

<uses-sdk android:minSdkVersion="7" />
<instrumentation 
    android:targetPackage="gml.android.mixdroid.test" 
    android:name="android.test.InstrumentationTestRunner" 

    android:label="Tests for MixDroid App"/>
<activity 
    android:name="gml.android.SeekbarActivity"/>
</manifest> 

在 Logcat 中我收到以下内容

[2011-04-03 03:51:48 - SeekbarTest] Project dependency found, installing: SeekbarActivity 
[2011-04-03 03:51:50 - SeekbarActivity] Application already deployed. No need to reinstall. 
[2011-04-03 03:51:50 - SeekbarTest] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 
[2011-04-03 03:51:53 - SeekbarTest] Collecting test information 
[2011-04-03 03:51:57 - SeekbarTest] Test run failed: Test run incomplete. Expected 1 tests, received 0

: JUnit视图,无信息测试

I'm new in Android dev apps and trying to use JUnit test framework to test the code below, with ActivityInstrumentationTestCase2 class, with lectures on TestingFundamentals in Android Docs. But when Test runs, I'm not getting any info about the tests (the red, green, blue bars in JUnit interface in Eclipse) (in fact, I believe that the tests are not occurring, even with the console saying yes).

Here are the JUnit code and Manifest Files:

package gml.android.mixdroid.test;
import java.util.ArrayList;
import gml.android.mixdroid.SeekbarActivity;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.SeekBar;
import android.widget.TextView;

public class SeekBarActivityTest extends ActivityInstrumentationTestCase2<SeekbarActivity> {

private SeekbarActivity mActivity;
private ArrayList<SeekBar> mSeekBars;
private ArrayList<TextView> mProgress;
private ArrayList<TextView> mTracks;

public SeekBarActivityTest(String pkg, Class<SeekbarActivity> activityClass) {
    super("gml.android.mixdroid", SeekbarActivity.class);
}

public void setUp() throws Exception{
     super.setUp();
     mActivity = getActivity();
     mSeekBars = mActivity.getSeekBars();
     mProgress = mActivity.getProgressTextViews();
     mTracks = mActivity.getTrackingTextViews();

}

public void testPreconditions(){
    assertNotNull(mSeekBars);
    assertNotNull(mProgress);
    assertNotNull(mTracks);
    for(SeekBar s : mSeekBars){
        assertNotNull(s);
    }
    for(TextView p : mProgress){
        assertNotNull(p);
    }
    for(TextView t : mTracks){
        assertNotNull(t);
    }
}

public void testInitSeekBars() {
    assertEquals(SeekbarActivity.NUMBER_OF_SEEK_BARS, mSeekBars.size());
}

public void testInitTextViews() {
    assertEquals(SeekbarActivity.NUMBER_OF_SEEK_BARS, mTracks.size());
    assertEquals(SeekbarActivity.NUMBER_OF_SEEK_BARS, mProgress.size());
}
}

Manifest (Activity):

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="gml.android.mixdroid"
  android:versionCode="1"
  android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".SeekbarActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>
<uses-sdk android:minSdkVersion="7" />

</manifest> 

Manifest( JUnit):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  android:versionCode="1"
  android:versionName="1.0" 
  package="gml.android.mixdroid.test">
<application 
    android:icon="@drawable/icon"
     android:label="@string/app_name">
     <uses-library android:name="android.test.runner" />
</application>

<uses-sdk android:minSdkVersion="7" />
<instrumentation 
    android:targetPackage="gml.android.mixdroid.test" 
    android:name="android.test.InstrumentationTestRunner" 

    android:label="Tests for MixDroid App"/>
<activity 
    android:name="gml.android.SeekbarActivity"/>
</manifest> 

In Logcat I receive this:

[2011-04-03 03:51:48 - SeekbarTest] Project dependency found, installing: SeekbarActivity 
[2011-04-03 03:51:50 - SeekbarActivity] Application already deployed. No need to reinstall. 
[2011-04-03 03:51:50 - SeekbarTest] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 
[2011-04-03 03:51:53 - SeekbarTest] Collecting test information 
[2011-04-03 03:51:57 - SeekbarTest] Test run failed: Test run incomplete. Expected 1 tests, received 0

and JUnit View, no info test

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵情客 2024-11-06 00:55:06

使用这个构造函数:

public SeekBarActivityTest() {
    super("gml.android.mixdroid", SeekbarActivity.class);
}

Use this constructor:

public SeekBarActivityTest() {
    super("gml.android.mixdroid", SeekbarActivity.class);
}
花开浅夏 2024-11-06 00:55:06
  1. 在 Eclipse 中,右键单击您的测试项目并运行为 -> Android JUnit 测试
  2. 在 DDMS 中检查 logcat,您将看到一些输出
  3. 如果一切顺利,您将在 JUnit 视图中看到测试结果
  1. In Eclipse, right click on your Test project and Run As -> Android JUnit Test
  2. Check logcat in DDMS, you will see some output
  3. If everything went well, you'll see the tests results in JUnit View
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文