You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: rework the create a test project page (#877)
* Retrieve the modifications from #875
* Update docs/site/docs/getting-started/create-test-project.md
Co-authored-by: Egil Hansen <[email protected]>
* Update docs/site/docs/getting-started/create-test-project.md
Co-authored-by: Egil Hansen <[email protected]>
* Refrase the parts related to .NET 7 and the project creation
* Remove duplicated space
* Refrase the mentions of the section moved upwards
Co-authored-by: Egil Hansen <[email protected]>
Copy file name to clipboardExpand all lines: docs/site/docs/getting-started/create-test-project.md
+78-70Lines changed: 78 additions & 70 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,78 @@ title: Creating a new bUnit test project
7
7
8
8
To write tests, you need a place to put them - a test project. bUnit is not a unit test runner, so a general-purpose test framework like xUnit, NUnit, or MSTest is needed in addition to bUnit in order to write and run tests.
9
9
10
-
To use bUnit, the easiest approach is to use the bUnit project template described in the [Create a test project with bUnit template](#creating-a-test-project-with-bunit-template) section further down the page. To create a test project manually and in a general-purpose testing frameworks agnostic way, read the following section.
10
+
To use bUnit, the easiest approach is to use the bUnit project template described in the following section. To create a test project manually and in a general-purpose testing frameworks agnostic way, read the section [Create a new test project](#create-a-new-test-project) section further down the page.
11
+
12
+
## Creating a test project with bUnit template
13
+
14
+
To quickly get started with bUnit, install and use the [bUnit test project template](https://www.nuget.org/packages/bunit.template/).
15
+
16
+
The steps for creating a test project with the bUnit template are as follows:
17
+
18
+
1. Install the template (only needed the first time)
19
+
2. Create a new bUnit test project
20
+
3. Add the test project to your solution
21
+
22
+
These steps look like this from the `dotnet` CLI:
23
+
24
+
**1. Install the template**
25
+
26
+
Install the template from NuGet using this command:
27
+
28
+
```dotnetcli
29
+
dotnet new --install bunit.template
30
+
```
31
+
32
+
Or, since .NET 7 onwards:
33
+
34
+
```dotnetcli
35
+
dotnet new install bunit.template
36
+
```
37
+
38
+
**2. Create a new test project**
39
+
40
+
If you successfully installed the template listed in the previous section, you
41
+
can create a new project directly from the "Create new project" wizard in Visual Studio (or Rider), where the bUnit project type will also show up.
42
+
43
+
Otherwise, use one of the following command to create a bUnit test project with
44
+
the framework of your choice:
45
+
46
+
# [xUnit](#tab/xunit)
47
+
48
+
```dotnetcli
49
+
dotnet new bunit --framework xunit -o <NAME OF TEST PROJECT>
50
+
```
51
+
52
+
# [NUnit](#tab/nunit)
53
+
54
+
```dotnetcli
55
+
dotnet new bunit --framework nunit -o <NAME OF TEST PROJECT>
56
+
```
57
+
58
+
# [MSTest](#tab/mstest)
59
+
60
+
```dotnetcli
61
+
dotnet new bunit --framework mstest -o <NAME OF TEST PROJECT>
62
+
```
63
+
64
+
***
65
+
66
+
The `--framework` option in the `dotnet new` command above is used to specify the unit testing framework used by the test project. If the `--framework` option is omitted, the default test framework `xunit` will be configured. Currently supported options are the following:
If using Visual Studio, add the test project to your solution (`.sln`), and add a reference between the test project and the project containing the components that should be tested:
75
+
76
+
```dotnetcli
77
+
dotnet sln <NAME OF PROJECT>.sln add <NAME OF TEST PROJECT>
78
+
dotnet add <NAME OF TEST PROJECT>.csproj reference <NAME OF COMPONENT PROJECT>.csproj
79
+
```
80
+
81
+
This will allow the test project to see and test the components in the component project.
11
82
12
83
## Creating a test project manually
13
84
@@ -116,7 +187,7 @@ The result should be a test project with a `.csproj` that looks like this (non b
116
187
<ItemGroup>
117
188
<ProjectReferenceInclude="<PATH TO COMPONENT LIB>.csproj" />
118
189
</ItemGroup>
119
-
190
+
120
191
</Project>
121
192
```
122
193
@@ -132,13 +203,13 @@ The result should be a test project with a `.csproj` that looks like this (non b
<ProjectReferenceInclude="<PATH TO COMPONENT LIB>.csproj" />
170
241
</ItemGroup>
171
242
172
243
</Project>
173
244
```
174
245
175
-
***
176
-
177
-
## Creating a test project with bUnit template
178
-
179
-
To skip a few steps in the guide above, use the [bUnit test project template](https://www.nuget.org/packages/bunit.template/).
180
-
181
-
The steps for creating a test project with the bUnit template are as follows:
182
-
183
-
1. Install the template (only needed the first time)
184
-
2. Create a new test project
185
-
3. Add the test project to your solution
186
-
187
-
These steps look like this from the `dotnet` CLI:
188
-
189
-
**1. Install the template**
190
-
191
-
Install the template from NuGet using this command:
192
-
193
-
```dotnetcli
194
-
dotnet new install bunit.template::#{NBGV_NuGetPackageVersion}#
195
-
```
196
-
197
-
**2. Create a new test project**
198
-
199
-
Use the following command to create a bUnit with xUnit test project:
200
-
201
-
# [xUnit](#tab/xunit)
202
-
203
-
```dotnetcli
204
-
dotnet new bunit --framework xunit -o <NAME OF TEST PROJECT>
205
-
```
206
-
207
-
# [NUnit](#tab/nunit)
208
-
209
-
```dotnetcli
210
-
dotnet new bunit --framework nunit -o <NAME OF TEST PROJECT>
211
-
```
212
-
213
-
# [MSTest](#tab/mstest)
214
-
215
-
```dotnetcli
216
-
dotnet new bunit --framework mstest -o <NAME OF TEST PROJECT>
217
-
```
218
-
219
-
***
220
-
221
-
The `--framework` option in the `dotnet new` command above is used to specify the unit testing framework used by the test project. If the `--framework` option is omitted, the default test framework `xunit` will be configured. Currently supported options are the following:
If using Visual Studio, add the test project to your solution (`.sln`), and add a reference between the test project and the project containing the components that should be tested:
230
-
231
-
```dotnetcli
232
-
dotnet sln <NAME OF PROJECT>.sln add <NAME OF TEST PROJECT>
233
-
dotnet add <NAME OF TEST PROJECT>.csproj reference <NAME OF COMPONENT PROJECT>.csproj
234
-
```
235
-
236
-
This will allow the test project to see and test the components in the component project.
237
-
238
246
## Further reading
239
247
240
248
To start creating tests, continue reading the <xref:writing-tests> page.
0 commit comments