vendredi 5 février 2016

Run test with accessible private field in tested class

I have some class with constant to test:

public class SomeClass {
     private static final String SOME_CONST = "blabla";

And I have to use it in test, so I make (with Spring ReflectionUtils and java.lang native arsenal) smth like:

findField(SomeClass.class, "SOME_CONST").setAccessible(true);

or

makeAccessible(findField(SomeClass.class, "SOME_CONST"));

Running test I see my Intellij Idea stops running with error related with trying to access private field. Suppose I should use some kind of @SuppressWarnings or how to solve such an issue better?





Aucun commentaire:

Enregistrer un commentaire