AndroidJUnit4 测试未找到

2024-05-07

我像这样注释了我的课程

@RunWith(AndroidJUnit4.class)
public class WorkdayProviderTest

此外,还注释了我的测试方法,如下所示

@Test
public void insert_dataInsertsCorrectly()

最后,像这样配置我的 build.gradle defaultConfig 和依赖项

defaultConfig {
    applicationId 'com.jueggs.workinghours'
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

androidTestCompile "junit:junit:4.12"
androidTestCompile "com.android.support:support-annotations:23.3.0"
androidTestCompile "com.android.support.test:runner:0.4.1"
androidTestCompile "com.android.support.test:rules:0.4.1"
androidTestCompile "com.android.support.test.espresso:espresso-core:2.2.1"
androidTestCompile "com.android.support.test.espresso:espresso-contrib:2.2.1"
androidTestCompile "org.hamcrest:hamcrest-library:1.3"

并像这样配置测试运行

它告诉我

No tests were found

Test running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'

如何解决这个问题?


您的 Gradle 依赖项中可能没有某些内容。你是否正确申报了com.android.support.test:runner(可选com.android.support.test:rules)?

请看一下我的build.gradle file:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.6'
    }
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName "com.piotr.testexample"
    }
}

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    useLibrary 'org.apache.http.legacy'

    //For building with Travis CI
    lintOptions {
        abortOnError false
    }

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    defaultConfig {
        applicationId "com.piotr.testexample"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    ext.JUNIT_VERSION = '4.12'
    ext.AA_VERSION = '4.0.0'
    ext.SUPPORT_VERSION = '23.3.0'
    ext.ESPRESSO_VERSION = '2.2.2'

    apt "org.androidannotations:androidannotations:$AA_VERSION"
    compile "org.androidannotations:androidannotations-api:$AA_VERSION"

    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile "junit:junit:$JUNIT_VERSION"
    testCompile("org.robolectric:robolectric:3.0") {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-provider-api'
    }

    compile "com.android.support:appcompat-v7:$SUPPORT_VERSION"
    compile "com.android.support:design:$SUPPORT_VERSION"
    compile "com.android.support:cardview-v7:$SUPPORT_VERSION"
    compile "com.android.support:recyclerview-v7:$SUPPORT_VERSION"

    compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'

    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.squareup.picasso:picasso:2.5.2'

    androidTestCompile "com.android.support:support-annotations:$SUPPORT_VERSION"
    androidTestCompile "com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION"
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile "com.android.support.test.espresso:espresso-intents:$ESPRESSO_VERSION"
    /**
     * AccessibilityChecks
     * CountingIdlingResource
     * DrawerActions
     * DrawerMatchers
     * PickerActions (Time and Date picker)
     * RecyclerViewActions
     */
    androidTestCompile("com.android.support.test.espresso:espresso-contrib:$ESPRESSO_VERSION") {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-v7'
        exclude group: 'com.android.support', module: 'design'
        exclude module: 'support-annotations'
        exclude module: 'recyclerview-v7'
    }

    compile "junit:junit:${JUNIT_VERSION}"
}

编辑:问题出在注释上,请执行以下解决方案之一:

  • delete @RunWith(AndroidJUnit4.class)
  • change @RunWith(AndroidJUnit4.class) with @RunWith(JUnit4.class)

好像没有了AndroidJUnit4.class在测试包中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AndroidJUnit4 测试未找到 的相关文章

  • Firebase 管理 SDK Android

    在 Android 中初始化 Firebase Admin SDK 的代码 Override protected void onCreate Bundle savedInstanceState super onCreate savedIns
  • Android 通知进度条冻结

    这是我正在使用的代码 http pastebin com 3bMCKURu http pastebin com 3bMCKURu 问题是 一段时间后 文件变得更重 通知栏下拉速度变慢 最后它就冻结了 你的通知太频繁了 这就是它冻结的原因 让
  • Android - 如何一次只允许播放一个 MediaPlayer 实例?

    我正在尝试创建一个简单的 Sound board Android 应用程序 使用 ListView 项目作为按钮 顺便说一句 我是一个新手程序员 我的想法是 我按下一个按钮 就会播放一个特定的声音文件 如果我在播放声音时按下任何按钮 它应该
  • 菜单未显示在应用程序中

    由于某种原因 我的操作菜单在我的 Android Studio 应用程序中消失了 我正在按照教程学习如何创建 Android 应用程序 但最终遇到了这个问题 我正在使用 atm 的教程 http www raywenderlich com
  • Android:“dp”到“px”转换?

    我正在读这篇文章 http developer android com guide practices screens support html http developer android com guide practices scre
  • KitKat(及更低版本)设备上的 Android Material Design

    我将在我们学校开发一个 Android 应用程序作为一个项目 我想使用 Google 的新 Material Design 但我知道它仅适用于 Android L 设备 Jack Underwood 最近发布了名为 Today Calend
  • 无法在自定义 AOSP 上安装 Google Play 中的某些应用程序:项目不可用。理由:9

    我在尝试从 Google Play 安装某些应用程序时收到以下错误 LibraryUtils isAvailable not available restriction 9 DocUtils getAvailabilityRestricti
  • 在 Android 中使用 DataOutputStream 在 POST 正文中发送特殊字符 (ë ä ï)

    我目前正在开发一个具有大量服务器端通信的 Android 应用程序 昨天 我收到一份错误报告 称用户无法发送 简单 特殊字符 例如 我搜索过但没有找到任何有用的东西 可能重复 没有答案 https stackoverflow com que
  • Android 原理图内容提供程序库配置?

    Jake Wharton 在最近的一次演讲中提到了这个库 它看起来是避免大量样板文件的好方法 所以我尝试了一下 但没有任何成功 https github com SimonVT schematic https github com Simo
  • TextView 之间有分隔线

    我正在尝试在 android studio 中创建以下布局 因为我对 android 东西还很陌生 所以我第一次尝试使用 LinearLayout 并认为这可能无法实现 现在我正在尝试使用RelativeLayout 我已经用颜色创建了这个
  • 更新到材质 1.2.0 后,材质按钮上缺少圆角半径属性

    这是我的材质按钮代码
  • 请求位置更新参数

    这就是 requestLocationUpdates 的样子 我使用它的方式 requestLocationUpdates String provider long minTime float minDistance LocationLis
  • 应用程序未安装在 Android 模拟器上

    我正在 android Geocoder 中开发一个应用程序 当我运行该应用程序时 它会显示 2011 01 11 11 08 13 GeoTourProject 自动目标模式 使用现有模拟器 emulator 5554 运行兼容的 AVD
  • Android 版 Robotium - solo.searchText () 不起作用

    我在使用 Robotium 时遇到 searchText 函数问题 我正在寻找这个字符串
  • 检查 Android 手机上的方向

    如何查看Android手机是横屏还是竖屏 当前配置用于确定要检索的资源 可从资源中获取Configuration object getResources getConfiguration orientation 您可以通过查看其值来检查方向
  • 如何将设备连接到Eclipse?

    我无法解决这个简单的问题 我正在尝试通过 USB 电缆将我的设备连接到 Eclipse 在我的 PC 上 我已经安装了 Eclipse 和 Android SDK 并且在模拟器上运行该程序运行良好 我已在我的电脑上下载并安装了 Samsun
  • 下载后从谷歌照片库检索图像

    我正在发起从图库中获取照片的意图 当我在图库中使用 Nexus 谷歌照片应用程序时 一切正常 但如果图像不在手机上 在 Google Photos 在线服务上 它会为我下载 选择图像后 我将图像发送到另一个活动进行裁剪 但在下载的情况下 发
  • 应用程序关闭时的倒计时问题

    我制作了一个 CountDownTimer 代码 我希望 CountDownTimer 在完成时重新启动 即使应用程序已关闭 但它仅在应用程序正在运行或重新启动应用程序时重新启动 因此 如果我在倒计时为 00 10 分钟 秒 时关闭应用程序
  • Android 如何聚焦当前位置

    您好 我有一个 Android 应用程序 可以在谷歌地图上找到您的位置 但是当我启动该应用程序时 它从非洲开始 而不是在我当前的城市 国家 位置等 我已经在developer android com上检查了信息与位置问题有关 但问题仍然存在
  • 用于推送通知的设备令牌

    我正在实施推送通知服务 我需要创建一个数据库来存储 4 个移动平台的所有设备令牌 我想根据他们的平台 iOS Android BlackBerry WP7 来组织它们 但是有什么方法可以区分平台 这样如果我只想向 Android 用户发送消

随机推荐

  • SQL - 用 varchar 替换 is null 整数

    我正在尝试用新的列替换列varchar如果 select 语句中存在空值 则为字符串 personid ISNULL personid no person 我不想更新它 只是在查询结果中将值显示为 无人 但我收到一条错误消息 将 varch
  • json_encode() 非 utf-8 字符串?

    所以我有一个字符串数组 并且所有字符串都使用系统默认值ANSI编码并从 SQL 数据库中提取 因此有 256 种不同的可能的字符字节值 单字节编码 有什么方法可以让我得到json encode 工作并显示这些字符而不必使用utf8 enco
  • VoiceOver 的 UISlider 可访问性特征?

    使 UISlider 在启用 VoiceOver 的情况下可用所需的正确 UIAccessibility 特征和处理程序是什么 是否有关于用户如何使用启用 VoiceOver 的 UISlider 的描述 以下是我最终添加到 UISlide
  • 使用 TextBox 过滤 Datagridview 行

    我有一个绑定的 datagridView 我想使用 TextBox 值对其进行过滤 我使用了这段代码 private void ChercheStextBox TextChanged object sender EventArgs e tr
  • 在php中如何设置数组的大小?

    我只想在 php 中设置数组的大小 而不必用任何值填充它 我怎么做 Use 固定阵列 http php net SplFixedArray对于固定大小的数组 array new SplFixedArray 3 array 0 1 array
  • 在 C# 中更改 Excel 单元格格式

    如何使用 C 中的 Microsoft Excel 12 0 库更改 Excel 中单元格的格式 更具体地说 我想将给定单元格更改为文本格式 我读过了 net c 改变Excel单元格格式 https stackoverflow com q
  • 向 UIControls 添加属性而不使用子类化

    我已将 UIButtons 嵌入到 TableViewCells 中 为了跟踪按钮属于哪个单元格 我想向 UIButton 添加 NSIndexPath 属性 我不想子类化 UIButton 有没有办法可以通过类别来做到这一点 编辑 我相信
  • 使用循环计算 Python 字典中元素的有效方法

    我有一个值列表 我希望在循环期间计算每个类的元素数量 即 1 2 3 4 5 mylist 1 1 1 1 1 1 2 3 2 2 2 2 3 3 4 5 5 5 5 mydict dict for index in mylist mydi
  • 当 tableView 向下滑动时显示 UISearchController

    我通过 UISearchController 在我的测试应用程序中实现了搜索栏 当我启动应用程序时 我会在导航控制器下方看到搜索栏 但如何在应用程序启动时隐藏它并仅在下拉表格视图时显示它 并在拉出表格视图时再次隐藏 我在google或you
  • 纹理不适用于网格 - OpenGL

    我正在使用 OpenGL Es 我已成功加载 obj 文件 网格 并且显示良好 但当我应用纹理时 它不显示 我添加了下面的代码 public void draw GL10 gl bind the previously generated t
  • 复制到其他计算机时无法在 WcfTestClient 中添加服务

    我想在另一台计算机上运行 WcfTestClient VS2012 中包含的一个 而不安装 VS2012 这可能吗 在我已经安装了 NET 4 5 的机器上 但是当我尝试添加 Web 服务时 它给了我以下堆栈跟踪 Exception Tex
  • 是否可以仅使用密码进行身份验证,即使设备在 ios、swift 中具有 touch id 功能

    我要认证only使用PassCode甚至设备有Touch ID特征 我在用着 deviceOwnerAuthentication评估政策方法 当我使用这个时 如果用户已注册触摸 ID gt 始终要求提供触摸 ID 如果用户尚未注册 touc
  • Django- CMS:占位符中的插件位置

    我正在寻找一种方法来检查插件在 Django CMS 占位符中的位置 我发现这个问题检测占位符中的最后一个插件 https stackoverflow com questions 5543947 detect last plugin in
  • 将元组划分为多个元组的类型安全方法

    我们有一个特征 除其他外 还包含execute T lt Record Seq Session gt T Seq T 方法 其中Record是我们从数据库中检索的所有特征的超级特征 trait DbTrait val threadCount
  • 如何将Windows服务中的参数从Installer传递到Program.cs中的Main函数?

    我已成功将参数从 Installutil 传递到我的 serviceinstaller 但我似乎无法将这些参数传递到 Main string args 函数 这就是我尝试做到这一点的方法 如果有更好的方法来做我正在做的事情请告诉我 prot
  • Javascript 沙箱模式示例实现

    在 Stoyan Stefanov 的伟大著作 JavaScript Patterns 的第 101 页中 他解释了沙箱模式 我非常喜欢他的书 但我真的错过了一些现实生活中的例子 然后更好地理解他所谈论的内容 我正在寻找一个现实生活中的工作
  • 无法解析符号“servlet”

    我有一个新手大问题 当我尝试以下操作时 servlet 变成红色并指示 无法解析符号 servlet import javax servlet http import javax servlet ServletException 我的 ap
  • 一个在 Java 中进行 URL 查询字符串操作的好库 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我需要用 Java 进行一些非常简单的 URL 操作 就像获取查询中参数的值或更新它一样 我希望在 commons lang 包中找到一个
  • 正在传输包... > 失败 以下步骤中发生错误。 `正在传输包...`(返回代码:2)未知错误

    当我在模拟器上部署 Tizen 项目时出现错误 正在传输包 gt 失败 在以下步骤中发生错误 Transferring the package 返回代码 2 未知错误 我该如何修复它 以及在我的模拟器中的开发人员模式下 这个问题的答案是 确
  • AndroidJUnit4 测试未找到

    我像这样注释了我的课程 RunWith AndroidJUnit4 class public class WorkdayProviderTest 此外 还注释了我的测试方法 如下所示 Test public void insert data