TDD for business applications works as follows.
Record the business requirement.
Record a test for this requirement.
Enter the code that passes the test.
The trick is that there are many dissimilar non-standard requirements that do not require rigorous testing.
Saving a database is not a requirement for a business. This is technical.
“activating a button in the GUI for any situation” is not a business requirement, it is part of the interface.
“backup” is not a business requirement; is it security or business continuity or something like that.
Consider a specific example.
The requirement is "You cannot borrow books until you pay your fines."
tests.
The code.
class FinesNotPaid( unittest.TestCase ): def setUp( self ):
These are business rules implemented by classes that are separate from your database and your GUI. These are application domain level classes.
Your CRUD rules are business rules. You need to test them. However, you do not need to check every database-related function. You need a few "can I create and save an object?" tests. You must believe that ORM, the data access layer, and the database really work. You do not write tests for exhaustive testing of built-in ORM functions.
Code coverage (100% or 80% or 10%) is pretty much pointless. Is software with tests with 80% code coverage actually 20% more likely to fail? This does not work. Testing every line of code does not cover every logical path, so stop worrying and start testing.
Check out business use cases. If they pass and there is unverified code, then - perhaps - you wrote too much code.
source share