@PowerMockIgnore will also ignore @PrepareForTest classes

610 views
Skip to first unread message

Hans

unread,
Jul 22, 2014, 3:25:46 PM7/22/14
to powe...@googlegroups.com
Hi,

i have a large project with some old junits and wanted to powermock to it. The project consists of XML, Java Security etc - lots of stuff that is not happy to be changed by the classloader of powermock.

Hence i wanted to ignore basically everything from powermock and only let it alter the few classes i need.

But the mocking will not work when i use @PowerMockIgnore for packages which includes the Class to be mocked.

E.g.

@PowerMockIgnore for org.myproject.*
@PrepareForTest org.myproject.SomeClass.class

PowerMock will show no errors during setup but the class will in the end not be mocked during test.

When i remove the ignore directives it works.

While im on the subject, it would be nice to simply not have powermock alter the classloader for anything but the few classes loaded with PrepareForTest - why isnt this done that way?

Thanks

Johan Haleby

unread,
Jul 23, 2014, 2:57:14 AM7/23/14
to powe...@googlegroups.com
Hmm I cannot really remember, I can not find a reason off the top of my head for it being this way. It would be great if you want to help out with this and file a pull request. 

/Johan


--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at http://groups.google.com/group/powermock.
For more options, visit https://groups.google.com/d/optout.

Hans

unread,
Aug 5, 2014, 8:18:11 AM8/5/14
to powe...@googlegroups.com
Sorry i have no idea about the interna of powermock and therefor im not suited to provide a patch.

This looks like a bug to me

linh đàm quang

unread,
Mar 21, 2018, 12:39:53 AM3/21/18
to PowerMock
For a long year. But hope that my answer can support for other ones.
If you put like that it will have an exception during building time because the Unittest Runner cannot find the TestClass
It's better if you add exactly the Ignore Class name in @PowerMockIgnore.
Ex:
@PowerMockIgnore({"jptools.*", "javax.xml.parsers.*", "org.xml.sax.*", "org.w3c.dom.*", "org.springframework.*", "com.crif.coredb.core.dataaccess.dao.AddressInRegistry*"})

If you must use the same @PowerMockIgnore in many test class, you can create an abstract class and extend it, in this abstract class you ignore all your expected classes.


Vào 02:25:46 UTC+7 Thứ Tư, ngày 23 tháng 7 năm 2014, Hans đã viết:
Reply all
Reply to author
Forward
0 new messages