1

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

Branch: junit5

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. Link 1
  2. Link 2

My whole code works perfectly with junit4 in master branch.

Please assist.

Reprator
  • 2,859
  • 2
  • 32
  • 55
  • 2
    With Android Studio Arctic fox 2020.3.1 i also have issue with JUnit5 tests with Test Events were not received error. You might also have the same issue. It took a day but still couldn't find a way to run JUnit5 tests with new android studio. Same tests work fine with JUnit4 – Thracian Aug 13 '21 at 08:41
  • Not sure but maybe you need to add some dependencies: junit-platform-launcher, junit-platform-engine? – dim42 Aug 13 '21 at 19:33
  • 1
    finally suite is accomplished with, testImplementation("org.junit.platform:junit-platform-suite:1.8.0-RC1") testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.0-RC1") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.0-RC1") Repo: https://github.com/TheReprator/Wipro/blob/master/appModules/factList/src/test/kotlin/reprator/wipro/factlist/FactListTestSuite.kt – Reprator Aug 22 '21 at 14:28

2 Answers2

0

I see you are using @RunWith(JUnitPlatform::class) which basically says "hey, please JUnit5, run my JUnit 4 tests!" but then you have used org.junit.jupiter.api.Test annotation, which tells the platform that those are JUnit5 tests.

So actually, there are no JUnit 4 tests to run.

I'd suggest you to drop the Suite at all and if you want test suites use nested classes. Or use Tag annotation to group tests.

By default, JUnit5 will run all @Test methods you have in the test src path. Check your gradle config for those.

  • i had even tried with tags, as well, but again same error, i am getting, "test events not received" – Reprator Aug 19 '21 at 07:53
0

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

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.

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.

  • first thanks for the time and effort you had put for it. Yes, the code runs fine "./gradlew appModules:factList:test --rerun-tasks" with ide or teminal but with my current scenario, i want to execute the set of test class with junit 5 suite, rather than individual – Reprator Aug 21 '21 at 05:18
  • No worries! I like to experiment and I saw your comment at my lastminute tech blog post. I'm not working there anymore and a colleage asked me to support you, part of our DNA culture ;) Regarding your question, I suggest you to use newer versions (snapshots, milestone) of JUnit 5, like: https://github.com/junit-team/junit5/issues/744 and the documentation at https://junit.org/junit5/docs/5.8.0-M1/user-guide/#test-suite This gives support for tests suites at JUnit5 like you want. Suite support is planned for 5.8 ;) – TarodBOFH Aug 21 '21 at 09:32
  • Wow, that great, u guys are really awesome, that even after leaving u are following it – Reprator Aug 21 '21 at 10:31
  • finally suite is accomplished with, testImplementation("org.junit.platform:junit-platform-suite:1.8.0-RC1") testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.0-RC1") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.0-RC1") Repo: https://github.com/TheReprator/Wipro/blob/master/appModules/factList/src/test/kotlin/reprator/wipro/factlist/FactListTestSuite.kt – Reprator Aug 22 '21 at 14:27
  • Glad it worked! – TarodBOFH Sep 20 '21 at 17:52