Software engineer from Argentina! I'm working as a FE engineer and from to to time I upload videos to my youtube channel https://www.youtube.com/frontendtopics
This is a good starting point! I'm not an expert on this topic, but unit testing seems easy when you test "pure" functions. What happens when you have different results for the same input? Or functions that just call functions and you have to start using spies? Would be great if you go deeper in those topics!
What happens when you have different results for the same input?
You implement it as a proper state machine and test each state independently. The vending machine Kata is a great example of just that. Man, that one drove me up the wall. I'd much prefer to just have functions that always return the same output given the same input.
Exactly! If you want to make your life as easy as possible, you'll have as high a percentage of pure functions as possible. This requires explicit effort.
While you can achieve purity in any language, functional programming languages let you achieve it far more easily.
Personally most side-effecting code I write is also externally facing code, which makes them Integration Tests rather than Unit tests.
I very rarely use spies/mocks and the like. Brittle.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a good starting point! I'm not an expert on this topic, but unit testing seems easy when you test "pure" functions. What happens when you have different results for the same input? Or functions that just call functions and you have to start using spies? Would be great if you go deeper in those topics!
You implement it as a proper state machine and test each state independently. The vending machine Kata is a great example of just that. Man, that one drove me up the wall. I'd much prefer to just have functions that always return the same output given the same input.
github.com/rubberduck203/VendingMa...
Great question!
Exactly! If you want to make your life as easy as possible, you'll have as high a percentage of pure functions as possible. This requires explicit effort.
While you can achieve purity in any language, functional programming languages let you achieve it far more easily.
Personally most side-effecting code I write is also externally facing code, which makes them Integration Tests rather than Unit tests.
I very rarely use spies/mocks and the like. Brittle.