> For the complete documentation index, see [llms.txt](https://dotnetweb30-ke.gitbook.io/ke/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dotnetweb30-ke.gitbook.io/ke/verification/automated-testing-principles-patterns-and-practices/styles-of-unit-testing-output-state-collaboration.md).

# Styles of Unit Testing (Output / State / Collaboration)

There are 3 major styles of unit testing:

* Output verification
* State verification
* Collaboration verification

### Output verification

{% hint style="success" %}
You pass some input to the system under test and **check what output** it produces.
{% endhint %}

![](https://3408508746-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lis5JLcnSD2vdYdyQ3U%2F-Lk8eE1CI4OTOO9ZI-vw%2F-Lk8ff1hnAjHPNTAodJ7%2Fimage.png?alt=media\&token=98592930-7063-4453-93b7-57871b6290de)

The yellow line here shows the point at which the examination is done.

In order to apply this style of unit testing, the system under test must not change global or internal state, so that the only component to verify would be its return value. This style of unit testing is also known as functional style. The "sut" method here doesn't leave any side effects and doesn't refer to the external world, its inputs and outputs are fully encoded with its method signature.

### State verification

{% hint style="success" %}
You **verify the state** of the system after the operation is completed.
{% endhint %}

![](https://3408508746-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lis5JLcnSD2vdYdyQ3U%2F-Lk8eE1CI4OTOO9ZI-vw%2F-Lk8gDwUX65Lekhmhkdm%2Fimage.png?alt=media\&token=46b52d92-81b6-401e-9c30-70d404684334)

The yellow circles on this picture represent that final state.

Unlike the previous sample, this method doesn't return any value, its outcome is the change made to its internal state.

### Collaboration verification

{% hint style="success" %}
You check that **all collaborators got invoked** in a correct order and with correct parameters.
{% endhint %}

![](https://3408508746-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lis5JLcnSD2vdYdyQ3U%2F-Lk8eE1CI4OTOO9ZI-vw%2F-Lk8hoWWpUHV9LPjcC7u%2Fimage.png?alt=media\&token=839827ae-1bf1-43d5-b825-eab05be02192)

This is normally done by substituting the collaborators with test doubles, such as **mocks**. For example, we create a fake implementation of the `IDatabase` interface which we then pass to the service. After that, the test verifies that the expected method was called and then the correct parameter was used.
