单元测试中不起作用

单元测试中不起作用

本文介绍了带有 SelectClasses 的 Junit5 testSuite 在 android 单元测试中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 android 应用程序的单元测试创​​建一个测试套件,但它总是因不同类型的配置错误而失败,其中之一如下,

i am trying to create a test suite for Unit test of android application, but it always fails with different kinds of configuration error, one among that is as follows,

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':appModules:factList:testDebugUnitTest'.
> No tests found for given includes: [reprator.wipro.factlist.FactListTestSuite]
 (filter.includeTestsMatching)

RepoDetails:https://github.com/TheReprator/Wipro/tree/junit5

RepoDetails: https://github.com/TheReprator/Wipro/tree/junit5

分支:junit5

TestSuite 类:https://github.com/TheReprator/Wipro/blob/junit5/appModules/factList/src/test/kotlin/reprator/wipro/factlist/FactListTestSuite.kt

TestSuite Class: https://github.com/TheReprator/Wipro/blob/junit5/appModules/factList/src/test/kotlin/reprator/wipro/factlist/FactListTestSuite.kt

我尝试了很多努力和参考,其中一些如下,

I had tried many efforts and references, some of them are as follows,

  1. 链接 1
  2. 链接 2

我的整个代码与 master 分支中的 junit4 完美配合.

My whole code works perfectly with junit4 in master branch.

请帮忙.

推荐答案

您是否使用 gradle 运行测试?因为我下载了你的分支,在没有 android studio 的情况下设置了一个环境(我的个人电脑没有安装开发环境),我在你的 JUnit 5 分支上得到了这个输出:

Are you using gradle to run your tests? Because I downloaded your branch, played a little bit to setup an environment without android studio (my personal computer has no dev environment installed) and I got this output on your JUnit 5 branch:

./gradlew appModules:factList:test --rerun-tasks

FactListDataRepositoryImplTest > get fact list from server, on internet connection available() PASSED

FactListDataRepositoryImplTest > No internet available() PASSED

FactListApiServiceTest > get fact list request check() PASSED

FactListApiServiceTest > Timeout example() PASSED

FactListApiServiceTest > get fact list successfully() PASSED

FactListRemoteDataSourceImplTest > fetch list successfully from server and map it to UI pojo() PASSED

FactListRemoteDataSourceImplTest > fetch list failed with errorBody() PASSED

FactListMapperTest > create the parsed json fact into FactModals class with title() PASSED

FactListUseCaseTest > fetch factlist from remote data source() PASSED

FactListUseCaseTest > failed to load data, as internet is not available() PASSED

FactListViewModalTest > onRefresh, getlist successfully() PASSED

FactListViewModalTest > retry, getFactlist successfully() PASSED

FactListViewModalTest > get factList fetch failed on launch() PASSED

FactListViewModalTest > get factList successfully on launch() PASSED

...

> Task :appModules:factList:testReleaseUnitTest
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

FactListDataRepositoryImplTest > get fact list from server, on internet connection available() PASSED

FactListDataRepositoryImplTest > No internet available() PASSED

FactListApiServiceTest > get fact list request check() PASSED

FactListApiServiceTest > Timeout example() PASSED

FactListApiServiceTest > get fact list successfully() PASSED

FactListRemoteDataSourceImplTest > fetch list successfully from server and map it to UI pojo() PASSED

FactListRemoteDataSourceImplTest > fetch list failed with errorBody() PASSED

FactListMapperTest > create the parsed json fact into FactModals class with title() PASSED

FactListUseCaseTest > fetch factlist from remote data source() PASSED

FactListUseCaseTest > failed to load data, as internet is not available() PASSED

FactListViewModalTest > onRefresh, getlist successfully() PASSED

FactListViewModalTest > retry, getFactlist successfully() PASSED

FactListViewModalTest > get factList fetch failed on launch() PASSED

FactListViewModalTest > get factList successfully on launch() PASSED

也许您需要将构建操作委托给 gradle(在 IntelliJ 上是可能的,在 Android Studio 上不确定)或清除您的项目设置或类似的东西.

Maybe you need to delegate build actions to gradle (it is possible on IntelliJ, not sure on Android Studio) or clear your project settings or something like that.

可能您正在尝试使用一个 Run Configuration 来运行您的套件,它是一个 JUnit4 套件并需要 JUnit4 测试,但您的测试是 JUnit5 测试.

Probably you are trying to use a Run Configuration that runs your suite, which is a JUnit4 Suite and expects JUnit4 tests but your tests are JUnit5 tests.

这篇关于带有 SelectClasses 的 Junit5 testSuite 在 android 单元测试中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 19:38