Mock final class with Mockito 2

前端 未结 7 1008
醉酒成梦
醉酒成梦 2020-12-01 12:31

I\'m removing Powermock from the project I\'m currently working on, so I\'m trying to rewrite some existing unitary test only with Mockito (mockito-core-2.2.28).

When

7条回答
  •  难免孤独
    2020-12-01 12:49

    I couldn't get it working with the configuration file either; however, the Mockito team is so kind and also provides a pre-configured Mockito artifact that requires no configuration in the target project.

    As a convenience, the Mockito team provides an artifact where this mock maker is preconfigured. Instead of using the mockito-core artifact, include the mockito-inline artifact in your project. Note that this artifact is likely to be discontinued once mocking of final classes and methods gets integrated into the default mock maker.

    So, if you use Gradle and want to test your Kotlin code, just add this to your project's dependencies:

    testCompile 'org.mockito:mockito-inline:2.8.9'
    testCompile('com.nhaarman:mockito-kotlin:1.5.0') {
        exclude group: 'org.jetbrains.kotlin'
        exclude group: 'org.mockito'
    }
    

提交回复
热议问题