I recently asked a question about design and got suggestion about how to structure my code. I'm still working on design so I only have pseudo code, but this is what I had in mind.
class TableManager()
{
int init(DBManager manager, String name)
{
this.name = name
this.manager = manager
}
int add_thing(Thing thing)
{
try {
manager.cursor.execute("INSERT INTO %s, (%s)) % (this.name, thing)
return 1
} catch {
return -1;
}
}
Initially I figured that you would unittest this by initializing TableManager in the unittest setup by passing it a DBManager connected to localhost and "TEST_TABLE" as the name argument.
Then you would call add_thing with various table states. For example, the first test would call add_thing with an initially empty table. The unittest would then check the status of the TEST_TABLE to make sure the added thing is in the table.
Is this considered integration testing or unit testing?
Someone mentioned using a MockDatabase to unit test the table manager. I don't see what that would do? You could create a MockDatabase which just returns true when execute is called, but I don't see how that would test the functionality of add_thing without actually having a database to make sure the element was added successfully.