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

Optional replacement of MockClassLoader.class.getClassLoader() via Annotation. #823

Open
NiciaB opened this issue Jul 28, 2017 · 6 comments

Comments

@NiciaB
Copy link

NiciaB commented Jul 28, 2017

We were using PowerMock 1.5.6 under Eclipse Mars for Junit tests.
With our migration to Eclipse Oxygen we also wanted to update PowerMock to 1.7, but we noticed, that there is no longer any support for OSGI, due to the classloading problems using PowerMock/OSGI.

As we have hundreds of test-cases using the PowerMockRunner, and we do not want to lose those testcases, and we do not have the time to redesign our code and junit tests. We modified the PowerMock sources, integrating some additional annotations to provide optionally some own class loader, instead of MockClassLoader.class.getClassLoader().

Right now, this is working fine for our hundreds of test-cases and we would like to contribute the changes to the next PowerMock release.

@thekingn0thing
Copy link
Member

thank you for willing to contribute to PowerMock. I think, it could be really useful if your changes could resolve OSGI issues. I think, better to create a pull request and then discuss changes.

I also want to bring your notice on powermock-byte-buddy branch where I've refactored MockClassLoader and started implementing ability to specify class loader in PrepareForTest annotation. This feature is required because I'm going to provide ability using ClassLoader that uses ByteBuddy for byte-code modification as experimental support at first. Maybe your changes could integrated with this changes?

NiciaB added a commit to NiciaB/powermock that referenced this issue Jul 30, 2017
NiciaB added a commit to NiciaB/powermock that referenced this issue Jul 30, 2017
NiciaB added a commit to NiciaB/powermock that referenced this issue Jul 30, 2017
…etClassLoader() via Annotation. (Fix JUnit)
NiciaB added a commit to NiciaB/powermock that referenced this issue Jul 30, 2017
…etClassLoader() via Annotation. (Fix JUnit)
NiciaB added a commit to NiciaB/powermock that referenced this issue Jul 30, 2017
…etClassLoader() via Annotation. (Fix JUnit)
@NiciaB
Copy link
Author

NiciaB commented Jul 30, 2017 via email

@NiciaB
Copy link
Author

NiciaB commented Jul 31, 2017 via email

@AndreasBrieg
Copy link

This would also solve problems the SAP hybris platform (https://hybris.com/) has with unit testing and powermock.

There some of the unit tests for web components are loaded using a classloader, but the powermock classes are being loaded with the parent of that classloader. Then MockClassLoader won't be able to load the unit test class to modify it since that class is only known to the child class loader that MockClassLoader is using.

@qupera
Copy link

qupera commented Feb 5, 2019

I'd like to add a comment on this as well. We are working with Hybris Platform 1811 and we exactly had the problems Andreas described in the comment above. The unit tests for web components were failing because the test classes couldn't be found (using the standard Mock Classloader)
With this enhancement we were able to fix this issue and now we can use PowerMock in our frontend component.
A big, big thank you to Nicole who fixes the problem.
So sad, that the pull request is still not integrated in the master branch.
I checked out the branch Nicole created and built PowerMock with this enhancement. It's working like a charm in our Hybris environment.

@dimitar-stoyanov-accenture

Hi @qupera ! I am currently facing similar issues with the class loader used in PowerMock tests for Hybris web components. Could you share what have you done to solve the issue?

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

No branches or pull requests

5 participants