“UNIT TESTING is a level of software testing where individual units/ components of a software are tested. The purpose is to validate that each unit of the software performs as designed. A unit is the smallest testable part of any software. It usually has one or a few inputs and usually a single output.”
Effective unit tests need Clean Code with a Testable design. Your tests need to be Context-aware, that is to say unit tests in project a may not hold the same value of tests in project b.
Also see this forked readme from Rusty Divine (http://osmyn.com/)
Unit of Work
Everything that happens from invoking a public method to it returning the results after it’s finished; it’s the work done along the path you see the debugger take through your code.
Unit Test
Code that invokes a unit of work within the confines of a project layer while faking external dependencies and validates an assumption about one specific scenario.
There are also Integration Tests and other testing stategies.
Stubs
A substitute for a dependency in the code under test that allows the code to compile and the dependency to return data as specified by the test but importantly cannot itself directly make a test fail.
- Example: Stub out external depednancy with wiremock.
Mocks
A substitute for a dependency in the code under test that knows how many times each of its methods were called an in what order so that it can validate an assumption about how the dependency was used and therefore make a test fail.
- Example: Mock out external depednancy with Moq.
Fakes
A generic term for a replacement of a real dependency with something the test specifies, which includes both stubs and mocks.
References
- https://ardalis.com/unit-test-naming-convention
- http://softwaretestingfundamentals.com/unit-testing/
- https://www.pluralsight.com/courses/csharp-unit-testing-enterprise-applications
- https://www.pluralsight.com/courses/basic-unit-testing-csharp-developers
- https://www.telerik.com/products/mocking/unit-testing.aspx