I am testing an SDK with many static methods. And I do not want the operations that I performed in test1 () to affect the operations that I perform in test2 (). At the beginning of each test, I need all the static variables in the SDK to return to an uninitialized state, as if they were not loaded. And then download them again. Any suggestions on how to do this? Are there any provisions in Robolectric? Because I use this for unit testing. In terms of English, what I basically want is a clean list at the beginning of each test.
@Test public void test1() throws Exception {
This was the first test, and he succeeded. It should be so. Then in the second test:
@Test public void test2() throws Exception {
I do not want the values ββset in the first test to affect the values ββobtained in the second test. The test shown above are simple examples. But the SDK, which I am unit testing, is more complex.
To make this clearer, I do not want the values ββset in test1 () to have any effect on the operations performed in test2 (). If I set the device model in Nexus 4 to test1 (), like this MyDeviceInfoClass.setDeviceModel (). Equals ("Nexus 4"), the second test test2 () should not know about it when I get it through MyDeviceInfoClass.setDeviceModel (). Equals ("Nexus 4"). I want complete isolation between my unit tests.
Also, abandoning static methods is not an option. Please tell me how I can achieve this.
EDIT: Resetting all static variables before the start of the test is not an option due to certain difficulties associated with the project.
source share