TDD django models
If you're trying to do Test Driven Development, is it sane to write tests that check the column type of your models as you write your models?开发者_开发问答
Like before you write your model, you write a test and say I want an ID field that is an integer field.
I think it's a bit overkill to test the underlying framework within your app testing, in general. Unless you have a suspicion that it isn't well-tested and/or it is something that may change a lot (say you live by developing against trunk), it should be a reasonable assumption that your framework will operate as advertised/documented.
Shouldn't tests test functionality rather than implementation? In other words, test that the field can store an integer, not that it is an IntegerField. Then if that gets changed to a BooleanField your test fails (assuming no coercion), but if it gets changed to a FloatField the test still passes, because it can still store an integer.
If you don't want to drive yourself crazy, you should focus on tests that will really help you. Testing that the id column is an integer isn't testing your code, it's testing Django. Even testing that "subject" is a string field isn't helping you much. Test that the models can do what they have to do.
精彩评论