-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Update unit test tutorials #1726
Conversation
@guardrex, |
I'm going to dogfood the commands just to make absolutely sure they comport with the sample code. |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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: | ||
``` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
LGTM. I'll |
Fixes #1591