-
Notifications
You must be signed in to change notification settings - Fork 72
Unit test with Set Environment Variables is running fine in my local but failing in Jenkins CI/CD build #62
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
Comments
Can you please post the stacktrace of the failing test. |
isUserAuthenticateSuccess(....xyz.XXXXTest) Time elapsed: 0.041 sec <<< ERROR! |
I am unsure if the env variable is not setting or else the @PowerMockIgnore({"javax.crypto."}) is not being effective. I am using the @PowerMockIgnore({"javax.crypto."}) in my test. |
The stacktrace contains no code of System Rules. Can you please show the test class. |
Here is my piece of code, where the jenkin job fails
where And my system rules in tests goes like this
|
You have to use
instead of
With System Rules 1.18.0 you don't even need the method
Please tell me whether the |
Still the issue exists.. isUserAuthenticateFailure(com.expedia.csp.refundTracker.WMRServiceTest) Time elapsed: 0.011 sec <<< FAILURE! The value _JG-2LaEyFvJ6HE8EANunpBWgEDFE is set as System variable |
Can you show me the declaration of |
I tried both the ways. declaring directly while setting the environment variables also, set the variable as private static final String and referencing that variable while setting the environment
also
both did not work. |
May I rephrase my question. Do you have the following line in your code?
|
In my unit test, I am mocking (using powermock) the environment variable that is got from the system environment, for which I am using the system rules. To answer your question, I have the below line in my code and in my unit test, I am mocking it with passing the actual value.
Now I am trying like this in my unit test
|
I think the problem is that I have one possible explanation for your problem. Let class A be the class with the static field If that assumption is correct then you can fix your test by changing the line
to
Can you please try this out and tell me about the result. Please also revert the experiment about initializing the rule. If you use System Rules 1.18.0 your code should look like
|
@stefanbirkner to as there are other dependent Static variables which define our business logic. All such static variables are defined in our Constants class, which is always used by every test. Your last post in this thread clearly explains it(I have verified by printing the variable value before and after the environment variable overwrite), however could you please provide any other way to tackle this issue? As a workaround, I have removed the final keyword and overriding its value in every JUnit using |
In my unit test, I am setting the environment variables using stefanbirkner library. In local it is working fine. but when build it using Jenkins CI/CD pipeline, the build is getting failed with reasons corresponding to set environement.
Any info to resolve the issue is appreciated.
The text was updated successfully, but these errors were encountered: