前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Android Gradle 插件】TestOptions 配置 ⑤ ( Test 单元测试配置类 | 设置包含或排除单元测试 | 设置堆大小 | 设置测试前后执行的逻辑 )

【Android Gradle 插件】TestOptions 配置 ⑤ ( Test 单元测试配置类 | 设置包含或排除单元测试 | 设置堆大小 | 设置测试前后执行的逻辑 )

作者头像
韩曙亮
发布2023-03-30 15:47:11
1K0
发布2023-03-30 15:47:11
举报
文章被收录于专栏:韩曙亮的移动开发专栏

文章目录

Android Plugin DSL Reference 参考文档 :

一、org.gradle.api.tasks.testing.Test 单元测试配置类


UnitTestOptions ( build.gradle#android#testOptions#unitTests ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.TestOptions.UnitTestOptions.html

org.gradle.api.tasks.testing.Test 单元测试配置类 : https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html

1、Test 单元测试配置回顾

在上一篇博客 【Android Gradle 插件】TestOptions 配置 ③ ( TestOptions#unitTests 脚本块配置 | UnitTestOptions 配置简介 ) 中 , 参考文档 https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html , 有如下单元测试配置示例 ;

Gradle 中 Test 单元测试配置类参考 :

代码语言:javascript
复制
 plugins {
     id 'java' // adds 'test' task
 }

 test {
   // Discover and execute JUnit4-based tests
   useJUnit()

   // Discover and execute TestNG-based tests
   useTestNG()

   // Discover and execute JUnit Platform-based tests
   useJUnitPlatform()

   // set a system property for the test JVM(s)
   systemProperty 'some.prop', 'value'

   // explicitly include or exclude tests
   include 'org/foo/**'
   exclude 'org/boo/**'

   // show standard out and standard error of the test JVM(s) on the console
   testLogging.showStandardStreams = true

   // set heap size for the test JVM(s)
   minHeapSize = "128m"
   maxHeapSize = "512m"

   // set JVM arguments for the test JVM(s)
   jvmArgs '-XX:MaxPermSize=256m'

   // listen to events in the test execution lifecycle
   beforeTest { descriptor ->
      logger.lifecycle("Running test: " + descriptor)
   }

   // Fail the 'test' task on the first test failure
   failFast = true

   // listen to standard out and standard error of the test JVM(s)
   onOutput { descriptor, event ->
      logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
   }
 }

2、设置包含或排除单元测试

设置单元测试中 包含 或 排除 哪些测试 ,

  • include 用于设置包含哪些测试 ,
  • exclude 用于设置排除哪些测试 ;
代码语言:javascript
复制
   // explicitly include or exclude tests
   include 'org/foo/**'
   exclude 'org/boo/**'

3、设置堆大小

设置单元测试的 JVM 的堆大小参数 :

代码语言:javascript
复制
   // set heap size for the test JVM(s)
   minHeapSize = "128m"
   maxHeapSize = "512m"

4、设置测试前执行的逻辑

配置测试前执行的逻辑 :

代码语言:javascript
复制
   // listen to events in the test execution lifecycle
   beforeTest { descriptor ->
      logger.lifecycle("Running test: " + descriptor)
   }

同理 afterTest 配置的是 测试后 执行的代码逻辑 ;

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、org.gradle.api.tasks.testing.Test 单元测试配置类
    • 1、Test 单元测试配置回顾
      • 2、设置包含或排除单元测试
        • 3、设置堆大小
          • 4、设置测试前执行的逻辑
          相关产品与服务
          腾讯云服务器利旧
          云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档