I'm finally starting out with unit testing, having known that I should be doing it for a while, but I have a few questions:
Unit testing follows a pretty common strategy - AAA, or Arrange, Act, Assert. First, arrange all preconditions for your test to run. Next, Act or execute your code. Lastly, assert the correct things happened.
A typical unit test contains 3 phases: First, it initializes a small piece of an application it wants to test (also known as the system under test, or SUT), then it applies some stimulus to the system under test (usually by calling a method on it), and finally, it observes the resulting behavior.
It's not hard to learn unit testing: The hard part is to make sure you write tests for all the possible scenarios, which will give you 100% confidence in your deployed codebase. The hard part comes when the existing code is not suitable for covering with unit testing. That kind of code is called legacy code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With