8000 Documentation "how to set up mockito-core as a Java agent" for Gradle Kotlin should be improved · Issue #3584 · mockito/mockito · GitHub
[go: up one dir, main page]

Skip to content
Documentation "how to set up mockito-core as a Java agent" for Gradle Kotlin should be improved #3584
@tdltdl

Description

@tdltdl

The current version of documentation recommends to set the jvmArgs as the jvmArgs

tasks {
    test {
        jvmArgs("-javaagent:${mockitoAgent.asPath}")
     }
}

This is working when only Mockito agent is in use. As soon as another agent is expected (example for code coverage), this will fail as this overrides any previously registered agent. It will also remove all previously set jvmArgs.

To reproduce:
Both from IntelliJ

  • Run tests requiring Mockito agent coinfigured as documented, it will succeed
  • Re-run the same test with coverage, test will fail

Fix
The fix is trivial, instead of setting the jvmArgs, we need to add the entry instead.

tasks {
    test {
        jvmArgs.add("-javaagent:${mockitoAgent.asPath}")
     }
}

Tested with Grade 8.12 and Mockito 5.15.2

See

* jvmArgs("-javaagent:${mockitoAgent.asPath}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0