I have this class that I wanted to build using TDD, but I failed. It’s a pretty basic class called SubMissions, and all it does is it fetches some data from an SQL database.
So it has methods like getSubMissionForPage(), getSubMissionFromId() etc..
I tried building it using TDD. My first test contained a call to getSubMissionPage(), which only purpose is to return data. So making this test fail is pretty darn hard, since it can return any data, I couldn’t come up with a way to make it fail.
I know making your test fail is the first step into knowing what to implement, but what do you do when there’s actually no way of failing a test?
Any time you’re relying on an external data source, your test can always fail. What if the connection is dropped to your DB? What if the table doesn’t exist that you’re trying to get data from? What if the data you get back is not the data you expect?
Testing classes that connect to DBs is a little more tricky than testing HelloWorld.java, because you need some way to mock the DB. You can learn more about Mock Objects here.
Short answer, your tests/software can ALWAYS fail. If you don’t think your test can fail, you’re not thinking hard enough about the problem space.