首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未找到类,使用androidTest 3.0.1在androidTest中使用空测试套件,

问未找到类,使用androidTest 3.0.1在androidTest中使用空测试套件,
EN

Stack Overflow用户
提问于 2017-12-25 15:32:14
回答 3查看 8.2K关注 0票数 16

我在运行androidTest时遇到了问题。

下面是我在gradle的设置:

代码语言:javascript
复制
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.blabla.shoppinglistapp"
    minSdkVersion 17
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
 }
}

ext.daggerVersion = '2.11'
ext.roomVersion = '1.0.0'
ext.mockitoVersion = '2.11.0'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-android:2.8.47'

androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"

// RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0'

// Room
implementation "android.arch.persistence.room:runtime:$roomVersion"
implementation "android.arch.persistence.room:rxjava2:$roomVersion"
kapt "android.arch.persistence.room:compiler:$roomVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.10"
androidTestImplementation "android.arch.persistence.room:testing:$roomVersion"

// Gson
implementation 'com.google.code.gson:gson:2.8.2'
}

下面是测试(这里几乎什么都没有):

代码语言:javascript
复制
@RunWith(AndroidJUnit4::class)
class ShoppingListDaoTest {
@Test
fun useAppContext() {
    // Context of the app under test.
    val appContext = InstrumentationRegistry.getTargetContext()
    assertEquals("com.blabla.shoppinglistapp", appContext.packageName)
}

private lateinit var database: ShoppingListDatabase

@Before
fun initDb() {
    // using an in-memory database because the information stored here disappears after test
    database = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(),
            ShoppingListDatabase::class.java)
            // allowing main thread queries, just for testing
            .allowMainThreadQueries()
            .build()
}

@After
fun closeDb() {
    database.close()
}


@Test fun testGetActiveShoppingListWhenNoActiveShoppingListInserted() {
    database.shoppingListDao().getActiveShoppingLists()
            .test()
            .assertNoValues()
}


}

当我尝试运行测试时,我得到了以下信息:

进程完成退出代码1类未找到:"com.blabla.shoppinglistapp.ShoppingListDaoTest"Empty测试套件。

而且它还没有开始

更新

我注意到了一些非常糟糕的事情。当我在androidTest中启动新项目并尝试运行默认androidTest时,它给出了已知的错误:

错误:Gradle: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2错误:查看日志获取详细信息

解决方法是将这一行添加到gradle.properties中:

android.enableAapt2=false

这是我以前在最初的项目中完成的步骤(我也遇到了这个错误)。不幸的是,之后它给了我错误从我的问题。因此,如何用aapt2来解决isse问题才是真正的问题。也见这里:AAPT2错误:检查日志中的详细信息,在修复androidTest不工作后

有什么想法吗?

EN

回答 3

Stack Overflow用户

发布于 2018-01-30 04:22:14

我也有同样的问题。每当我试图运行单个测试或测试类时,我都会得到“空测试套件”错误。这似乎是Android Studio中的一个bug。

相反,右键单击androidTest包,然后单击"Run‘Test in .“,这是我让它工作的唯一方法。

提供:codelab的人

更新

这在Android Studio 3.1版本中是固定的。就连gradlew connectedDebugAndroidTest 问题现在也修好了。

票数 13
EN

Stack Overflow用户

发布于 2018-07-29 15:50:09

我也有同样的问题。在我的例子中,解决问题的方法是将我的测试类(DaoTest类)迁移到与Android创建的默认ExampleInstrumentedTest相同的包中。

我以前有过这样的项目结构:

  • 钢筋混凝土
    • androidTest
      • java
        • 我的应用程序包
          • ExampleInstrumentedTest
          • itemList.dataSource
          • DaoTest

​

​

​

​

​

改为:

  • 钢筋混凝土
    • androidTest
      • java
        • 我的应用程序包
          • ExampleInstrumentedTest
          • DaoTest

​

​

​

​

在这样做之后,我能够一次运行类中的所有测试,而没有任何问题。

票数 0
EN

Stack Overflow用户

发布于 2021-04-07 07:59:52

我想您运行测试文件的方式是不正确的。

首先,使缓存失效/重新启动,然后从编号栏运行测试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47969959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档