Mocking PluginManager

36 views
Skip to first unread message

Hosh

unread,
Nov 10, 2020, 2:43:07 PM11/10/20
to Jenkins Developers
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

Ullrich Hafner

unread,
Nov 10, 2020, 5:40:26 PM11/10/20
to Jenkins Developers
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. 
--
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 jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/2415979d-575e-4033-8b37-fd6686bce140n%40googlegroups.com.

Hosh

unread,
Nov 12, 2020, 7:46:17 AM11/12/20
to Jenkins Developers
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?
Reply all
Reply to author
Forward
0 new messages