4
donuts
6y

How do you think about unit testing/TDD when writing apps? (I'm working this at 3am so might be a bit messy... Just a thought I woke up to).

Whenever I write an app, I don't write unit tests but as I'm developing I may create test functions for specific parts that I run to validate a specific component is working before moving onto the next.

So first, when I get a problem, break it up into components based on the requirements. It's usually sort of input, processor, output sequence.

Where the processor is essentially the core app. And so I start coding it, referring to the input thru an interface, model objects, adding fields as I go along (assume no matter what the input, I will get these before the logic is called). I may add some more interfaces as well for other data I may need but I know won't be going in the first input.

So I write all the logic, functions needed to get a basic app to run that does what I am writing the app for.

Only then do I write a test functions passing in different parameters to make sure the logic and response is what I want and making fixes as necessary. At that point I basically have the simplest version of the app.
(I guess this is sort of like mocking?)

Then build outwards implementing and testing components as I go along and may do some simple refactoring/redesign. (I guess all these tests are functional then, have to start the whole app).

And finally when I have the basic requirements fully complete I will add the "nice to haves" on top via refactoring of specific logic in specific components. Again testing by running the app maybe with simple inputs.

I guess now I'm thinking how do you write unit tests/TDD if the app keeps changing (via adhoc refactorings) as you are creating it?

Comments
Add Comment