当前位置: 首页 > 知识库问答 >
问题:

有没有办法在带有gradle和pitest的突变下运行仪器化的Android测试?

聂昱
2023-03-14

我有一套安装了仪器的Android测试,在模拟设备上运行。我可以使用<code>gradlew connectedDebugAndroidTest</code>与gradle一起运行它们,并且我已经设置了gradle pitest插件,如下所示:

buildscript {
    repositories {
        google()
        jcenter()
        mavenLocal()
        mavenCentral()
    }
    configurations.maybeCreate('pitest')
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath 'com.google.ar.sceneform:plugin:1.13.0'
        classpath 'pl.droidsonroids.gradle:gradle-pitest-plugin:0.2.2'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'pl.droidsonroids.pitest'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "my.application.id"
        minSdkVersion 28
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled = true
        }
    }
    useLibrary 'android.test.runner'
    useLibrary 'android.test.base'
    useLibrary 'android.test.mock'
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    // Provides ARCore Session and related resources.
    implementation 'com.google.ar:core:1.13.0'
    // Provides ArFragment, and other Sceneform UX resources:
    implementation "com.google.ar.sceneform.ux:sceneform-ux:1.13.0"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    testImplementation "org.mockito:mockito-core:+"

    // AndroidX Test dependencies
    // Core library
    androidTestImplementation 'androidx.test:core:1.0.0'

    // AndroidJUnitRunner and JUnit Rules
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.0'

    // Assertions
    androidTestImplementation 'androidx.test.ext:junit:1.0.0'
    androidTestImplementation 'androidx.test.ext:truth:1.0.0'
    androidTestImplementation 'com.google.truth:truth:0.42'

    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0'
    androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0'

    // The following Espresso dependency can be either "implementation"
    // or "androidTestImplementation", depending on whether you want the
    // dependency to appear on your APK's compile classpath or the test APK
    // classpath.
    androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    androidTestImplementation "org.mockito:mockito-android:+"
    implementation 'org.pitest:pitest:1.4.5'
}

pitest {
    targetClasses = ['class.to.test.*']
    threads = 5
    outputFormats = ['HTML']
    verbose = true
}

当我运行 gradlew pitestgradlew pitestDebug 时,模拟器不会启动,只有我的单元测试会运行。在最可怜的配置中指定经过检测的测试类或指定其他测试运行程序没有帮助。我是Android Studio的新手,并且使用gradle配置突变测试,所以我不确定我是否错过了一些简单的东西,或者这绝对是不可能的。

共有2个答案

贺乐意
2023-03-14

如果你在测试单一的用户界面,而不需要像他们说的那样添加仪器:如果你在测试中使用替代的Android框架,像Robolectric或UnMock Gradle插件,你可能想添加excludemokableandroidjar到pitest配置

pitest {
targetClasses = ['com.myapp.*']
excludeMockableAndroidJar = true

}

端木皓君
2023-03-14

更新:根据gradle-Pitest-plugin的维护者的说法,没有PITest插件是不可能的。

 类似资料:
  • 问题内容: 我们正在开发S60版本,该平台具有不错的Python API。 但是,关于Android上的Python尚无任何官方资料,但是由于Jython存在,有没有办法让蛇和机器人一起工作? 问题答案: 一种方法是使用: 开源Python库,用于快速开发利用创新用户界面的应用程序,例如多点触控应用程序。 可在和上运行。你可以在所有受支持的平台上运行相同的代码。

  • 尝试在maven中重新访问Junit 5平台(5.3.2)下运行Junit 5/4集成测试。从如何使用maven failsafe插件并行运行JUnit 4和JUnit 5测试 在surefire插件2.22.1下运行单元测试可以并行和混合测试JUnit 5和JUnit 4,并在详细信息中查看工作线程。 在故障安全2.22.1中尝试了同样的方法,但是需要日志时间,并且似乎没有并行执行。而且只有[m

  • 有没有办法在Docker内部运行LXD?eg. 在使用ubuntu 16.04的主机上: 在容器中: LXD守护进程可以工作,但由于cgroups错误,我无法启动LXD容器。 我也尝试过:

  • 我有一个用Maven建立的Java项目,我正在用Cucumber和jUnit进行测试。 也许我遗漏了一些东西,但是有没有一种方法可以设置Cucumber测试运行程序来自动运行jUnit测试以及Cucumber特性?不必运行两个单独的测试套件,并使用自动测试所有内容,这将是一件非常棒的事情。 目前,当我指定时,它只查找文件并忽略所有其他测试。 以下是我的测试文件结构: 还有我的测试运行程序,它目前只

  • 据我所知,在Google Cloud Run上部署容器有两种方式: 云运行完全管理:它由GCP独立管理,无需我们创建集群 云运行for Anthos:这需要我们创建一个支持云运行的GKE集群 我想选择第二个选项,但希望将GKE集群保持为私有,这样就不允许任何外部通信。

  • 我解释我这篇文章的目标。 实际上,我想重写如何Android工作的基本上,与应用程序中的字符串。此时此刻,我可以从重写android资源中动态更改它 实际上,我有这个功能,只有当我使用时才能正常工作: 有一种简单的方法,不需要太多代码,就可以覆盖xml中的行为?