News for hackers. Stuff that matters.
Re:Questions to ask yourself when writing tests by lmm on Tuesday January 02, 2018 @03:23AM (#16050647)
Rather than having 3 different business logic methods that call out to the database, you have each construct a command object and then have a separate service that calls out to the database based on these commands. You can then test the 3 business logic methods by testing that they construct the correct commands based on their parameters.
Re:Questions to ask yourself when writing tests by falsedan on Tuesday January 02, 2018 @05:33AM (#16051082)
Yeah, exactly. To put it another way: get your business logic components to return data structures (a list of DB actions or an updated dict), and your core controller to turn those data structures into DB calls. Then your tests simply say: here’s a certain environment, what action do you think should be performed?

If you think this sounds like mocking, you’re right (it is like mocking, it isn’t mocking). It has the bonus of making it easier to inspect the logic & expose it to the user ("hey I’m about to do these things, does that sound ok to you?").

Re:Questions to ask yourself when writing tests by yeukhon on Tuesday January 02, 2018 @08:07AM (#16051614)
Thank you. Would you mind to elaborate a little more with perhaps a little pseudo-code snippet?
Re:Questions to ask yourself when writing tests by lmm on Wednesday January 03, 2018 @11:18AM (#16062226)
https://michaelxavier.net/posts/2014-04-27-Cool-Idea-Free-Mo... is a nice simple example if you don't mind reading Haskell. (Redis rather than a database, but the technique is the same)