Skip to content

Commit 80432b5

Browse files
author
Arthur Aulicino
committed
2 parents a1f4cb1 + e45b4a8 commit 80432b5

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Unity Coroutines for NSubstitute
22
========
33
[![Tests](https://github.com/AAulicino/Unity-Coroutines-for-NSubstitute/actions/workflows/main.yml/badge.svg)](https://github.com/AAulicino/Unity-Coroutines-for-NSubstitute/actions/workflows/main.yml)
4+
5+
- [Unity Coroutines for NSubstitute](#unity-coroutines-for-nsubstitute)
6+
* [What is it?](#what-is-it)
7+
* [Installation](#installation)
8+
* [Basic use](#basic-use)
9+
+ [Creating the mock](#creating-the-mock)
10+
+ [Using the mock](#using-the-mock)
11+
+ [Custom Assertions](#custom-assertions)
12+
413
## What is it?
514

615
Testing and mocking Unity Coroutines can be tricky. This is an extension for
@@ -73,7 +82,7 @@ Let's use this simple counter class for testing:
7382
while (true)
7483
{
7584
Current++;
76-
yield return null;
85+
yield return new WaitForSeconds(1);
7786
}
7887
}
7988
}
@@ -116,4 +125,28 @@ public class GameSetup : MonoBehaviour, ICoroutineRunner
116125
}
117126
```
118127

128+
### Custom Assertions
129+
130+
You can also assert the yielded values from the coroutine:
131+
132+
```csharp
133+
ICoroutineRunner runner = CoroutineSubstitute.Create();
134+
Counter counter = new Counter(Runner);
135+
136+
Runner.MoveNextAndExpect<WaitForSeconds>();
137+
```
138+
139+
To assert the amount of seconds configured in the `WaitForSeconds` object:
140+
```csharp
141+
ICoroutineRunner runner = CoroutineSubstitute.Create();
142+
Counter counter = new Counter(Runner);
143+
144+
Runner.MoveNextAndExpect(new WaitForSeconds(1));
145+
```
146+
147+
119148
Other samples can be found in the [Samples](https://github.com/AAulicino/Unity-Coroutines-for-NSubstitute/tree/main/Tests/Editor/Samples) folder.
149+
150+
---
151+
152+
You can also have a look at the [SystemTests](https://github.com/AAulicino/Unity-Coroutines-for-NSubstitute/tree/main/Tests/Editor/SystemTests) folder as the tests found in there represent some real uses cases.

0 commit comments

Comments
 (0)