Mocking PluginManager

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Mocking PluginManager

Hosh
Hi all,

I'm trying to write some tests for some changes I made to the datadog plugin at the request of the maintainer. The tests should ideally mock the PluginManager that JenkinsRule uses as I'm trying to test that the code is returning certain numbers based on what plugins are installed (e.g. active, inactive, updatable plugins etc)..

The problem however is that I am unable toset the plugin manager when trying to mock it. I've tried using new JenkinsRule().with(mock(PluginManager.class)), but this seemed to cause issues in the rest of the code, setting the plugin manager in any other way complains that the plugin manager is already set.

For reference, the PR is located here: https://github.com/jenkinsci/datadog-plugin/pull/156

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/2415979d-575e-4033-8b37-fd6686bce140n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Mocking PluginManager

Ulli Hafner
It would be much simpler if you change the way you access the PluginManager. I am using a Facade (https://github.com/jenkinsci/plugin-util-api-plugin/blob/master/src/main/java/io/jenkins/plugins/util/JenkinsFacade.java) for all calls to the running Jenkins instance in my plugins. This facade then can be replaced by a stub in your tests. 



Am 10.11.2020 um 19:39 schrieb Hosh <[hidden email]>:

Hi all,

I'm trying to write some tests for some changes I made to the datadog plugin at the request of the maintainer. The tests should ideally mock the PluginManager that JenkinsRule uses as I'm trying to test that the code is returning certain numbers based on what plugins are installed (e.g. active, inactive, updatable plugins etc)..

The problem however is that I am unable toset the plugin manager when trying to mock it. I've tried using new JenkinsRule().with(mock(PluginManager.class)), but this seemed to cause issues in the rest of the code, setting the plugin manager in any other way complains that the plugin manager is already set.

For reference, the PR is located here: https://github.com/jenkinsci/datadog-plugin/pull/156

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/2415979d-575e-4033-8b37-fd6686bce140n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/C0EA5EE5-2CD4-48EF-99C5-F909304ACA8F%40gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Mocking PluginManager

Hosh
Thanks, this definitely would solve the problem, though it seems like a big refactor for a plugin I don't maintain.

I will ask the maintainers to see if this such a PR would be acceptable. Meanwhile, do you have any other thoughts?

On Tuesday, November 10, 2020 at 10:40:26 PM UTC [hidden email] wrote:
It would be much simpler if you change the way you access the PluginManager. I am using a Facade (https://github.com/jenkinsci/plugin-util-api-plugin/blob/master/src/main/java/io/jenkins/plugins/util/JenkinsFacade.java) for all calls to the running Jenkins instance in my plugins. This facade then can be replaced by a stub in your tests. 
Am 10.11.2020 um 19:39 schrieb Hosh <[hidden email]>:

Hi all,

I'm trying to write some tests for some changes I made to the datadog plugin at the request of the maintainer. The tests should ideally mock the PluginManager that JenkinsRule uses as I'm trying to test that the code is returning certain numbers based on what plugins are installed (e.g. active, inactive, updatable plugins etc)..

The problem however is that I am unable toset the plugin manager when trying to mock it. I've tried using new JenkinsRule().with(mock(PluginManager.class)), but this seemed to cause issues in the rest of the code, setting the plugin manager in any other way complains that the plugin manager is already set.

For reference, the PR is located here: https://github.com/jenkinsci/datadog-plugin/pull/156

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/2415979d-575e-4033-8b37-fd6686bce140n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/e70cd019-8d10-4774-b88d-d12732003a93n%40googlegroups.com.