Testing Getters and Setters Considered Useful
Posted: June 22, 2011 | Author: simeshev | Filed under: Software | Leave a comment »Writing unit tests for getters and setters is a good idea because such tests create a regression detection suite.
I sometimes hear the argument that setters and getters are not worth unit testing. The logic goes that as they don’t do anything, there is nothing to test. There is a couple of problems with this attitude:
- First problem: It uses proof by assertion (“Trust me, this method doesn’t do anything [special]”), which is impossible to verify using automated testing tools such as JUnit.
- Second problem: The behavior of a setter or a getter may expand in future (such as storing the property in a database), and when it happens, there won’t be a unit test to verify that methods still do what they are supposed to do.
Writing a unit test for setters and getters, as trivial as they are at the moment, creates a regression detection suite. This is important because if future changes to the method break it, the unit test will be there to catch the problem.
To make testing matching pairs of setters and getters easier, I usually test them in a single method testSetGet() instead of the pair testSet() and testGet():
Bean:
public class Bean { private String property; public String getProperty() { return property; } public void setProperty(final String property) { this.property = property; } }
Test method:
/** * Tests setting and getting the property. */ public void testSetGetProperty() { final String testValue = "Test value"; assertNull("Initial value should be null", bean.getProperty()); bean.setProperty(testValue); assertEquals("Getter should return value set", testValue, bean.getProperty()); }
Test getters and setters and enjoy the benefits of the growing regression detection suite and the reliability of well-tested codebase.
Is intelligence gathered at Osama Bin Laden’s worth anything?
Posted: June 16, 2011 | Author: simeshev | Filed under: General | Leave a comment »Is it possible that a terrorist, known worldwide as being wanted dead or alive by the U.S. Government would keep top-secret and important documents at his hideout spot?
Let’s be serious here, Bin Laden was no fool; with most of the world searching for him and bounty rewards in the millions of dollars; Bin Laden knew he would eventually be caught.
Now the true question is if the documents found at his place of death were real or falsified. There is absolutely no way that Bin Laden would have kept such documents with him at all times. Documents with information on future attacks and how they would happen are targeted to a very limited amount of people.
The biggest reason that Bin Laden left the documents behind would be to confuse the U.S. government. This could be a very simple method to distract others from the actual targets.
The best way to deal with these documents would be to treat them with extreme suspicion and realize that someone who had such great power over so many people could not possibly have been that sloppy in his work. Does anyone really think that Bin Laden would have given the U.S. government advice on other terrorists?