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

How to test some pipeline steps without mock ? #100

Open
PavelKa opened this issue Apr 27, 2021 · 2 comments
Open

How to test some pipeline steps without mock ? #100

PavelKa opened this issue Apr 27, 2021 · 2 comments

Comments

@PavelKa
Copy link

PavelKa commented Apr 27, 2021

Desired Behavior

I have simple class method wich I want to test :

static def getAllProperties(script,configDir,appId ) {
   def envProperties = script.readProperties file:  "${configDir}/env.properties"
    def props =  script.readProperties   default: envProperties ,file: "${configDir}/${appId}/env.properties"
    props
  }

I'm using JenkinsPipelineSpecification to write tests in my project but in this case, readProperties are mocked and test will not detect that I have typo in parameter default. Also, the compiler will not fail. Is it possible to set up a test to fail or somehow configure to really call readProperties step ? Mocking using
1 * getPipelineMock("readProperties")(default:["x":"valueX"],file:"./appId/env.properties") >> ["y" : "valueY"] doesn't help as there is same typo as in the method implementation

Benefits

  1. Detecting such typos during a test is much more efficient than deploy to Jenkins and test manually
@awittha
Copy link
Contributor

awittha commented Aug 17, 2021

I am not quite sure I understand the question. It sounds like you're asking:

Assuming

  1. a function takes in a map of arguments
  2. One of the arguments' names is default

e.g. getAllProperties(default: ["x": "valueX")

Then

I would like a unit-test failure if my code calls this function with a typo, e.g.

getAllProperties(deflat: ["x": "valueX")

Is that correct?

@PavelKa
Copy link
Author

PavelKa commented Aug 18, 2021

Yes, that's what I need. There is method readProperties ( from the "Pipeline Utility Steps plugin") which expects "defaults" on input in my example, but I used "default". The test passes because I also used "default" in the getPipelineMock. I would like to find these types of errors/typos before deploying to Jenkins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants