Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create NUnit 3.0 glue library page for AutoFixture #20

Merged
merged 8 commits into from
Sep 1, 2020

Conversation

Kralizek
Copy link
Contributor

Creates the page containing information about the AutoFixture.NUnit3 package.

Fixes #16

@Kralizek Kralizek marked this pull request as ready for review August 28, 2020 15:36
@Kralizek
Copy link
Contributor Author

@elindanielsson, @agnerh
The page is ready for your review :)

@@ -0,0 +1,275 @@
AutoFixture offers a glue library for NUnit 3.0. In AutoFixture's lingo, a glue library is a library that extend one library (in this case NUnit 3.0) with AutoFixture.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a short description on why we want to use the glue library here? I can see some advantages mentioned in the text below but I think it would be nice to have it in the intro text here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

By using this library, developers can speed up the process of creating unit tests and, while doing so, creating unit tests that are easier to read.

Comment on lines 17 to 46
[Test]
[AutoData]
public void Echo_returns_same_message(Service sut, string message)
{
// ACT
var result = sut.Echo(message);

// ASSERT
Assert.That(result, Is.EqualTo(message));
}
```

The unit test above can be converted to the equivalent without taking advantage of the `AutoData` attribute.

```csharp
[Test]
public void Echo_returns_same_message()
{
// ARRANGE
var fixture = new Fixture();
var sut = fixture.Create<Service>();
var message = fixture.Create<string>();

// ACT
var result = sut.Echo(message);

// ASSERT
Assert.That(result, Is.EqualTo(message));
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be easier to parse if the "old" way is comes before the "new" way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

docs/NUnit-glue-library.md Outdated Show resolved Hide resolved
Comment on lines +55 to +56


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add few lines here about what the benefits of using AutoData instead of arranging manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Assert.That(result, Is.EqualTo(first + second));
}
```
As shown above, unlike the `AutoData` attribute, the `InlineAutoData` attribute can be applied more than once on the same unit test. Each instance of the attribute will generate a new execution of the unit test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expand a bit more on how the example above will run? How many executions and with what parameters in which execution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


Another issue deriving from delegating AutoFixture of instantiating classes like system under tests is the loss of control on which constructor is picked. By default, AutoFixture picks the constructor with least parameters, but sometimes this is not the optimal choice.

The `Greedy` and `Modest` attributes give the developer the power to instruct AutoFixture which constructor to select when constructing an object to be passed to NUnit. The `Greedy` attribute will instruct AutoFixture to use the constructor with the most parameters while the `Modest` attribute will instruct AutoFixture in the opposite way.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the opposite way

The opposite way how?
If it's just picking the constructor with the least parameters then why would someone use it since it's the default behavior?

Could we also add a short sentence about the scenario when the constructor you want to pick is neither the one with the most or the least parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, the need for [Modest] is unclear to me too.

Kralizek and others added 4 commits August 31, 2020 11:49
Co-authored-by: Henrik Agner <32951545+agnerh@users.noreply.github.com>
@Kralizek Kralizek requested a review from agnerh August 31, 2020 13:29
@Kralizek Kralizek mentioned this pull request Aug 31, 2020
@Kralizek Kralizek linked an issue Aug 31, 2020 that may be closed by this pull request
@Kralizek Kralizek merged commit 6555103 into keghub:master Sep 1, 2020
@Kralizek Kralizek deleted the glue-nunit branch September 16, 2020 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Migrate to GitBook AutoFixture - Create page for NUnit 3.0 glue library
2 participants