Replies: 1 comment 1 reply
|
You're right - You can. That warning is to make the code clear on intent. People may think that fields are seen by all tests, which isn't the case, and so the If a test has a value, why does it need to persist it in a field? It's setting the value just to retrieve it again? You can use fields, that analyzer was just an attempt to make things clearer to people. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
According to the test lifecycle overview, each test is executed within the context of a unique instance of the test class. Why then, is it not advisable to mutate instance fields on the class? That seems perfectly safe, and occasionally useful.
I find it particularly shocking that the analyzer advice is:
Why on earth would it be preferable to mutate
staticfields? That would certainly cause concurrency issues with other tests.All reactions