Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added test to increase test coverage for LabelParameterDefinition #229

Conversation

sherlockbeard
Copy link
Contributor

@sherlockbeard sherlockbeard requested a review from a team as a code owner May 1, 2023 20:02
@sherlockbeard
Copy link
Contributor Author

How do I create StaplerRequest object and what value should be there to mock it ?

public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
// as String from UI: {"labels":"built-in","name":"HOSTN"}
// as JSONArray: {"name":"HOSTN","value":["built-in","host2"]}
// as String from script: {"name":"HOSTN","value":"built-in"}

@MarkEWaite
Copy link
Contributor

How do I create StaplerRequest object and what value should be there to mock it ?

public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
// as String from UI: {"labels":"built-in","name":"HOSTN"}
// as JSONArray: {"name":"HOSTN","value":["built-in","host2"]}
// as String from script: {"name":"HOSTN","value":"built-in"}

Don't attempt to create a mock of a stapler request. Use a JenkinsRule test to things that need Stapler.

Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much!

@MarkEWaite MarkEWaite merged commit 7899dd7 into jenkinsci:master May 1, 2023
@MarkEWaite MarkEWaite added the test Automated test addition or improvement label May 1, 2023
@sherlockbeard
Copy link
Contributor Author

How do I create StaplerRequest object and what value should be there to mock it ?

public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
// as String from UI: {"labels":"built-in","name":"HOSTN"}
// as JSONArray: {"name":"HOSTN","value":["built-in","host2"]}
// as String from script: {"name":"HOSTN","value":"built-in"}

Don't attempt to create a mock of a stapler request. Use a JenkinsRule test to things that need Stapler.

I found one example with mock .

https://github.com/jenkinsci/custom-folder-icon-plugin/blob/2fe2b7118f7c15d39b75c77f9b6c70cfdfe6d6d3/src/test/java/jenkins/plugins/foldericon/utils/TestUtils.java#L68-L73

Is there any example with Jenkins rules? or which method to use to create request ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Automated test addition or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants