jeudi 2 juin 2022

reset static field to their initial value using reflexion in java

I use in my project a lib with some class with a lot of static field and other stuffs, who are indirectly updated and consulted at runtime in my app. I can't update or ignore or mock this class.

How can I re-execute the method who initialise the static field of a class?

I'm currently writing test in my app, which trigger this class. I want the static field of this class to be at their init state each time I start my app.

The issue is, setting manualy those static field is not possible, it would be too complexe. I need them to be put at their initial state "automaticaly"

I can't change anything to the code of the class, because it's in a lib.

Any idea how I can do that? With reflexion, maybe?





Aucun commentaire:

Enregistrer un commentaire