> For the complete documentation index, see [llms.txt](https://lwang010.gitbook.io/longw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lwang010.gitbook.io/longw/mlops/chap-4.-build-toolkit-for-team-or-yourself/tips/unit-test.md).

# unit test

1. unit test

use `unittest.TestCase`  or  pytest or nose.&#x20;

For the tensorflow based test, there is a \`tf.test\`.

\--> for tensorflow:

**Data**

* Ensure that our data has the **right format** (yes I put it again here for completion)
* Ensure that the **training labels are correct**
* **Test our complex processing steps** such as image manipulation
* **Assert data completion**, quality, and errors
* Test the distribution of the features

**Training**

* Run a training step and compare the weight before and after to ensure that they are updated
* Check that our loss function can be actually used on our data

**Evaluation:**

* Having tests to ensure that your metrics ( e.g accuracy, precision, and recall ) are above a threshold when iterating over different architectures
* You can run speed/benchmark tests on training to catch possible overfitting
* Of course, cross-validation can be in the form of a unit test

**Model Architecture:**

* The model’s layers are actually stacking
* The model’s output has the correct shape

2\. mocking&#x20;

Mocking makes it very easy to replace complex logic or heavy dependencies when testing code using dummy objects.&#x20;

3\. coverage
