I read from "How to run test methods in specific order in JUnit4?" that...
making tests order dependent is a practice that the authors don't want to promote. Tests should be independent, they shouldn't be coupled and violating this will make things harder to maintain
How, in that case, should I test a method that gets a certain piece of data when I first have to set it?
For example, I have a String getStringAttribute(String key)
and void setStringAttribute(String key, String attr)
. How should I test each of them? In order to properly test getStringAttribute()
, I would probably need to test getting something that is not yet set and testing something that is already set.
Should I use setStringAttribute()
within the testGetStringAttribute()
?