Magento 2 - What is Unit Test?

Unit Test is the smallest part of testing in Magento 2. Module must has classes and each class must has method(s) on it, that method contains lot of logic, each method return can be null, string, integer, false, etc. So this is where unit test works, we pass conditions and expected returns of passed conditions. for instance:

  1. there is 1 method called getProductBySku($sku), it maybe retuns the product instance or NULL because the SKU doesn't exist.

  2. so we need to create 2 tests for these conditions.


References: