Question

I've seen that some developers are using some methods (namely getInternalState()/setInternalState) from the Whitebox class.

My question is whether this is a good practice or not? I ask this because this class is in the package org.mockito.internal.util.reflection and usually classes within an internal package are not meant to be used by the outside world.

Était-ce utile?

La solution

If you take a look at the code, it is not a big deal at all. See here: https://code.google.com/p/mockito/source/browse/src/org/mockito/internal/util/reflection/Whitebox.java?r=9772247b067621ed5c3cefc356397b0bde5b89f6

If it is moved, you can do a full replace on the test code, which takes 2 minutes. If it will be deleted somehow from Mockito (which is not likely I think), then you can duplicate the class to your code (~50 lines). If there is any change, your tests will be broken, and you will see, that you need to change them. No real chance to get hidden problems.

So I would simply use it in test codes if neccessary.

Autres conseils

Late answer, but as I am just running into that:

I think it is bad practice to use anything that carries the name "internal".

And for me, it leads to considerable effort: I am right now updating our huge project setup and find that quite some folks have used exactly that thing.

And because of that; I can't upgrade our setup to the sane mockito 2.6.2; but I guess I am forced to go with powermock 1.66 / mockito 2.0.42; because some people thought it "OK" to use that internal class for their tests.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top