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

Update unit test tutorials #1726

Merged
merged 7 commits into from Mar 20, 2017
Merged

Update unit test tutorials #1726

merged 7 commits into from Mar 20, 2017

Conversation

guardrex
Copy link
Contributor

Fixes #1591

  • Reorganizes the setup to reflect the steps needed to establish the project folder
  • Calls out either walking thru the tutorial building the samples or taking them down from GH (Note that exactly how that will be done/instructed is WIP: Need: Instructions on how to download samples #1644)
  • Grammar/style overhaul
  • Samples updated for 1.1 and latest stable packages

@guardrex guardrex added doc-enhancement Improve the current content [org][type][category] update labels Mar 14, 2017
@guardrex guardrex added this to the March 2017 milestone Mar 14, 2017
@guardrex guardrex self-assigned this Mar 14, 2017
@dnfclas
Copy link

dnfclas commented Mar 14, 2017

@guardrex,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

@guardrex guardrex removed the WIP label Mar 14, 2017
@guardrex guardrex changed the title [WIP] Update unit test tutorials Update unit test tutorials Mar 14, 2017
@guardrex guardrex added the WIP label Mar 14, 2017
@guardrex
Copy link
Contributor Author

I'm going to dogfood the commands just to make absolutely sure they comport with the sample code.

Copy link
Contributor

@mairaw mairaw left a comment

Choose a reason for hiding this comment

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

Thanks @guardrex. I think overall it looks great. I've left a few comments.


[View or download sample code](https://github.com/dotnet/docs/tree/master/samples/core/getting-started/unit-testing-using-dotnet-test)
[Writing Libraries with Cross Platform Tools](../tutorials/libraries.md) has information on organizing multi-project solutions for both the source and the tests. This tutorial follows those conventions. This tutorial takes you through an interactive experience building a sample solution step-by-step to learn unit testing concepts. If you prefer to follow the tutorial using a pre-built solution, [view or download the sample code](https://github.com/dotnet/docs/tree/master/samples/core/getting-started/unit-testing-using-dotnet-test/) before you begin.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd remove or move the first two sentences especially because that topic is now outdated. Also, it seems odd to open the topic with that. Also, I kind of liked having the final structure shown early.


By [Steve Smith](http://ardalis.com) and [Bill Wagner](https://github.com/BillWagner)
## Creating the projects
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for a section here.

has information on organizing multi-project solutions for both the
source and the tests. This article follows those conventions. The
final project structure will be something like this:
Open a shell window. Create a directory to hold the solution, *unit-testing-using-dotnet-test*. Start in the *unit-testing-using-dotnet-test* directory and create a *PrimeService* directory. The directory structure thus far is shown below:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion for flow: Create a directory called unit-testing-using-dotnet-test to hold the solution. Inside this new directory, create a PrimeService directory.

`dotnet new` added xUnit, and the xUnit runner. You need to add the PrimeService
package as another dependency to the project. You can do that using the `dotnet`
CLI:
The test project requires other packages to create and run unit tests. `dotnet new` in the previous step added xUnit and the xUnit runner. Now, add the `PrimeService` class library as another dependency to the project. Use the `dotnet` CLI:
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the dotnet CLI -> You can do that using the dotnet add reference command. (you can link to the command too)

then repeating the process. So, let's write that one failing test. Remove
`UnitTest1.cs` from the `PrimeService.Tests` directory, and create a new
C# file named `PrimeService_IsPrimeShould.cs` with the following content:
The TDD approach calls for writing one failing test, making it pass, then repeating the process. Now, write one failing test: Remove *UnitTest1.cs* from the *PrimeService.Tests* directory and create a new C# file named *PrimeService_IsPrimeShould.cs* with the following content:
Copy link
Contributor

Choose a reason for hiding this comment

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

Now, write one failing test -> the old sentence looked better 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.

So, let's write that one failing test.

The conjunction and 1st person are problems. I can remove the whole sentence ... it isn't really needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's just remove it. It's fluff.

@@ -142,68 +114,37 @@ namespace Prime.UnitTests.Services
}
```

The `[Fact]` attribute denotes a method as a single test.
The `[Fact]` attribute denotes a method as a single test. Execute `dotnet test` to build the tests and the class library and then run the tests. The xUnit test runner contains the program entry point to run your tests. `dotnet test` starts the test runner and provides a command-line argument to the test runner indicating the assembly that contains your tests.
Copy link
Contributor

Choose a reason for hiding this comment

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

I kind of like to link to the commands page when we mention them but it's not a requirement


The example provides a service that indicates whether a number is prime.
## Restore and test
Copy link
Contributor

Choose a reason for hiding this comment

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

you can run just the app too, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not runnable ... class lib. AFAIK one has to run the test command. That's the way the original author had it. They had you restoring the lib and running build, but those steps aren't necessary. All they have to do is dotnet restore and dotnet test in the tests project. It restores both, builds both, and runs the tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh yeah, never mind... duh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do you think I feel? ..... On the first pass, I gave the darn blasted thing an entry point! lol

Copy link
Contributor

@mairaw mairaw left a comment

Choose a reason for hiding this comment

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

Looks great! I have a small question that would apply to both. @BillWagner do you wanna take a look at this?


The generated template configured the test runner
in the PrimeServiceTests.csproj:
```
Copy link
Contributor

Choose a reason for hiding this comment

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

should we show this after you do the dotnet new xunit so you have the full project structure somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Easy enough to add ... do you want me to pop it in there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@guardrex guardrex removed the WIP label Mar 17, 2017
@BillWagner
Copy link
Member

LGTM. I'll :shipit:

@BillWagner BillWagner merged commit ff14358 into dotnet:master Mar 20, 2017
@guardrex guardrex deleted the guardrex/unit-testing-tutorials-update branch March 20, 2017 22:13
@guardrex guardrex removed this from the March 2017 milestone Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement Improve the current content [org][type][category]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants