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
[AutoFixture.NUnit2](https://github.com/AutoFixture/AutoFixture.NUnit2) is a .NET library that integrates [AutoFixture](https://github.com/AutoFixture/AutoFixture) with NUnit 2.x, allowing you to effortlessly generate test data for your unit tests.
9
+
By automatically populating your test parameters, it helps you write cleaner, more maintainable tests without having to manually construct test objects.
13
10
14
-
AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.
15
-
16
-
Check the [testimonials](https://github.com/AutoFixture/AutoFixture/wiki/Who-uses-AutoFixture) to see what other people have to say about AutoFixture.
11
+
> [!WARNING]
12
+
> While this package is still being developed, the NUnit 2 package is deprecated.<br/>
13
+
> This package is intended for legacy projects that are still using NUnit 2.x.<br/>
14
+
> Use at your own risk.
17
15
18
16
## Table of Contents
19
17
20
-
-[Overview](#overview)
21
-
-[Downloads](#downloads)
22
-
-[Documentation](#documentation)
23
-
-[Feedback & Questions](#feedback--questions)
18
+
-[Installation](#installation)
19
+
-[Getting Started](#getting-started)
20
+
-[Integrations](#integrations)
24
21
-[License](#license)
25
22
26
-
## Overview
27
-
28
-
(Jump straight to the [CheatSheet](https://github.com/AutoFixture/AutoFixture/wiki/Cheat-Sheet) if you just want to see some code samples right away.)
29
-
30
-
AutoFixture is designed to make Test-Driven Development more productive and unit tests more refactoring-safe. It does so by removing the need for hand-coding anonymous variables as part of a test's Fixture Setup phase. Among other features, it offers a generic implementation of the [Test Data Builder](http://www.natpryce.com/articles/000714.html) pattern.
23
+
## Installation
31
24
32
-
When writing unit tests, you typically need to create some objects that represent the initial state of the test. Often, an API will force you to specify much more data than you really care about, so you frequently end up creating objects that has no influence on the test, simply to make the code compile.
25
+
AutoFixture packages are distributed via NuGet.<br />
26
+
To install the packages you can use the integrated package manager of your IDE, the .NET CLI, or reference the package directly in your project file.
33
27
34
-
AutoFixture can help by creating such [Anonymous Variables](https://docs.microsoft.com/en-us/archive/blogs/ploeh/anonymous-variables) for you. Here's a simple example:
This example illustrates the basic principle of AutoFixture: It can create values of virtually any type without the need for you to explicitly define which values should be used. The number *expectedNumber* is created by a call to `Create<T>` - this will create a 'nice', regular integer value, saving you the effort of explicitly coming up with one.
36
+
## Getting Started
53
37
54
-
The example also illustrates how AutoFixture can be used as a [SUT Factory](http://blog.ploeh.dk/2009/02/13/SUTFactory.aspx) that creates the actual System Under Test (the MyClass instance).
38
+
### Basic Usage
55
39
56
-
Given the right combination of unit testing framework and extensions for AutoFixture, we can further reduce the above test to be even more declarative:
40
+
`AutoFixture.NUnit2` provides an `[AutoData]` attribute that automatically populates test method parameters with generated data.
Notice how we can reduce unit tests to state only the relevant parts of the test. The rest (variables, Fixture object) is relegated to attributes and parameter values that are supplied automatically by AutoFixture. The test is now only two lines of code.
73
+
### Freezing Dependencies
81
74
82
-
Using AutoFixture is as easy as referencing the library and creating a new instance of the Fixture class!
75
+
AutoFixture's `[Frozen]` attribute can be used to ensure that the same instance of a dependency is injected into multiple parameters.
83
76
84
-
## Downloads
77
+
For example, if you have a consumer class that depends on a shared dependency:
85
78
86
-
AutoFixture packages are distributed via NuGet.<br />
87
-
To install the packages you can use the integrated package manager of your IDE, the .NET CLI, or reference the package directly in your project file.
You can freeze the Dependency so that all requests for it within the test will return the same instance:
94
+
95
+
```c#
96
+
usingNUnit.Framework;
97
+
usingAutoFixture.NUnit2;
98
+
usingAutoFixture;
99
+
100
+
[TestFixture]
101
+
publicclassConsumerTests
102
+
{
103
+
[Test, AutoData]
104
+
publicvoidConsumer_UsesSameDependency(
105
+
[Frozen] Dependencydependency, Consumerconsumer)
106
+
{
107
+
// Assert
108
+
Assert.AreSame(dependency, consumer.Dependency);
109
+
}
110
+
}
95
111
```
96
112
113
+
## Integrations
114
+
97
115
AutoFixture offers a variety of utility packages and integrations with most of the major mocking libraries and testing frameworks.
98
116
117
+
> [!NOTE]
118
+
> Since AutoFixture tries maintain compatibility with a large number of package versions, the packages bundled with AutoFixture might not contain the latest features of your (e.g. mocking) library.<br />
119
+
> Make sure to install the latest version of the integrated library package, alongside the AutoFixture packages.
120
+
99
121
### Core packages
100
122
101
123
The core packages offer the full set of AutoFixture's features without requring any testing framework or third party integration.
@@ -118,10 +140,6 @@ These integrations enable such features as configuring mocks, auto-injecting moc
> Since AutoFixture tries maintain compatibility with a large number of package versions, the packages bundled with AutoFixture might not contain the latest features of your mocking library.<br />
123
-
> Make sure to install the latest version of the mocking library package, alongside the AutoFixture package.
124
-
125
143
### Testing frameworks
126
144
127
145
AutoFixture offers integrations with most major .NET testing frameworks.<br />
@@ -139,41 +157,14 @@ These integrations enable auto-generation of test cases, combining auto-generate
139
157
140
158
You can check the compatibility with your target framework version on the [wiki](https://github.com/AutoFixture/AutoFixture/wiki#net-platforms-compatibility-table) or on the [NuGet](https://www.nuget.org/profiles/AutoFixture) website.
141
159
142
-
### vNext feed
143
-
144
-
The artifacts of the next major version are published to [nuget.org](https://www.nuget.org), and are marked with the `preview` suffix (e.g. `5.0.0-preview00007`).</br>
145
-
You can use these packages to early access and test the next major version of the AutoFixture.</br>
146
-
Make sure to enable the preview packages in your IDE in order to see the latest version.
147
-
148
-
> __NOTE:__ This preview versions exists for the _preview purpose_ only, so use them with caution:
149
-
>
150
-
>* New versions of packages might contain breaking changes and API could change drastically from package to package. By other words, we don't follow the SemVer policy for the packages in this feed;
151
-
>* Preview packages might be unlisted over time, in order to not clutter the version suggestion dialog in IDEs, but will generally remain available
Contributions to `AutoFixture.NUnit2` are welcome!
163
+
If you would like to contribute, please review our [contributing guidelines](https://github.com/AutoFixture/AutoFixture.NUnit2/blob/master/CONTRIBUTING.md) and open an issue or pull request.
173
164
174
165
## License
175
166
176
-
AutoFixture is Open Source software and is released under the [MIT license](https://raw.githubusercontent.com/AutoFixture/AutoFixture/master/LICENCE.txt).<br />
167
+
AutoFixture is Open Source software and is released under the [MIT license](https://raw.githubusercontent.com/AutoFixture/AutoFixture.NUnit2/master/LICENCE.txt).<br />
177
168
The licenses allows the use of AutoFixture libraries in free and commercial applications and libraries without restrictions.
0 commit comments