As a newbie to the development under test, I just ran into a problem. My test class starts as follows:
@RunWith(SpringJUnit4ClassRunner.class) @Transactional @DirtiesContext @ContextConfiguration(locations = {"/web-test.xml"}) public class XXTest { @Autowired XX xx; @Autowired HibernateTemplate template; @Test public void testSetGetXXValue() throws Exception { final Map<String, YY> profilMap = new HashMap<String, YY>(2); profilMap.put("1", new YY()); profilMap.put("2", new YY()); simpleCockpit.setValues(profilMap); assertEquals(profilMap, simpleCockpit.getValues()); }
As you can see, the first test method changes the auto-level class XX. This affects all subsequent testing methods that are based on XX, which have auto-support values.
How can I test getter and setter from XX and make sure that XX has values ββfor all other testing methods?
Thoughts:
- Reset the correct values ββat the end of the test method. Bad, because if the getter / setter does not work, this also will not work.
- Put the first test method at the end of the test class. Bad because it makes tests dependent on their order of execution.
- Do not check getter / setter XX. Bad, because getter / setter needs to be tested, like every method.
Thanks for answers! I am sure this is a simple solution ... :)
EDIT . Regarding questions about whether unit tests were getters / seters or not, I decided to do this mainly due to statet reasons at http://www.sundog.net/sunblog/posts/should-we-test-getters- and-setters / .
source share