Writing Mockito enabled JUnit test cases using Gradle

We are using the Gradle-based build system to create modules using the MicroEJ SDK in Android Studio IDE. We are running into the following issues:

  1. Using Mockito to write tests: We were able to add Mockito-enabled tests to the project however the tests failed as they ran in the MicroEJ VM. How do I switch to using the J2SE VM while using the Gradle Build system? We were referring to this post, however, how do we do the same in Gradle? Unit tests with Mockito

  2. Generate Test Report and Coverage Report for the tests: While using the MicroEJ IDE and Ivy-based build system, the test report is auto-generated when the tests are executed. Also, there are options to generate the coverage report using the generated .cc files. (as discussed here: Test Suite with JUnit — MicroEJ Documentation) How can similar reports be generated while using the Gradle-based build system and Android Studio?

Note:

  • We are exploring the use of Android Studio and Gradle as an environment for our projects
  • We would need the tests to run on the Virtual device

Any help in this regard will be appreciated.

Hi,

  1. Did you follow the documentation related to J2SE VM tests? The main difference is to use useJUnitJupiter() instead of microej.useMicroejTestEngine(this) in the testsuite configuration block. Please note that some improvements and bug fixes come in the upcoming 0.16.0 version which will be available in the coming days.
  2. The test reports are available in the file build/testsuite/output/<date>/testsuite-report.xml (see documentation on test report). It is only available as JUnit XML file for the moment, but will soon be available as HTML (like in SDK 5).
    As for the code coverage, we can generate it with the Code Coverage Analyzer and the execTool Gradle task, as described in this documentation.

Hope this helps,
Regards

Hi,

We tried to generate the code coverage (.cc) file using gradle command - gradle :runOnSimulator -D"s3.cc.thread.period=15" -D"s3.cc.activated=true" as per the given documentation
But we are getting the below error given in the screenshot

Any help in this regard will be appreciated.

Hi nitin123,

Can you create a dedicated forum topic please? This is not related to the current forum topic.

Your problem is probably because there more than one Maven repositories declared in your init scripts (in <USER_HOME>/.gradle/init.d), in the block:

configure<PublishingExtension> {
        repositories {
                ...
        }
}