xUnit has an interesting approach to exception handling for unit tests It’s different from the MSTest technique. This tutorial shows how to use the Assert.Throws and Record.Test methods to properly assert that an exception should happen during a unit test.
- [Voiceover] XUnit has an interesting approach…to exception-handling for unit tests.…It's different from the MS Test technique.…For a discussion of the philosophy…of unit tests and exceptions,…watch the expected exceptions video in the MS Test chapter.…I'll review what's happening in Brokerage Lib.…In this method determined variable rate,…I check whether the unit sold is less than zero,…and I also check whether the unit price is less than zero,…and if either of those conditions is true,…I throw the argument out of range exception.…Over in my unit test, I verify…that that exception is thrown by using…this expected exception attribute on my test method.…
I tell it I'm looking for argument out of range exception.…This states that the system under…test will throw this exception.…Let's review what happens when you have…an un-handled exception in your code.…Let's say that the exception is thrown on line ten.…Since there's no handler for it inside this method,…none of the rest of the code in this method will run.…That's also true over here in my test method.…
Author
Updated
8/29/2017Released
6/16/2016- Examining types of frameworks
- Choosing a naming convention
- Creating unit tests
- Running unit tests with Visual Studio
- Modifying and correcting code
- Handling exceptions
- Installing and using nUnit
- Viewing test results with CodeLens
Skill Level Beginner
Duration
Views
Q: This course was updated on 08/22/2017. What changed?
A: New videos were added that cover live unit testing and creating a project with the unit test framework.
Related Courses
-
Introduction
-
Welcome59s
-
-
1. Create a Simple Unit Test Framework
-
What are unit tests?6m 23s
-
Add the test projects1m 14s
-
Analyze which tests to run2m 10s
-
Create a simple test4m 45s
-
Create a simple test runner3m 46s
-
Add additional tests2m 59s
-
Refactor the test runner3m 59s
-
Create an Assert class5m 20s
-
Use the Assert class3m 49s
-
-
2. Unit Testing Conventions
-
Choose a naming convention5m 59s
-
-
3. Work with Visual Studio Unit Testing Framework
-
Create the unit test4m 16s
-
Run the unit test3m 21s
-
Modify code to pass test4m 53s
-
Expected exceptions4m 27s
-
Test parameters4m 9s
-
4. Work with xUnit
-
Install xUnit2m 21s
-
Expected exceptions4m 55s
-
Test multiple parameters2m 13s
-
-
5. Work with nUnit
-
Install nUnit2m 9s
-
Create and run a unit test2m 25s
-
Use the nUnit constraints3m 44s
-
More nUnit constraints6m 16s
-
Test parameters2m 21s
-
-
6. Additional Topics
-
Get more from your tests4m 40s
-
Debug unit tests2m 8s
-
Use the test menus3m 27s
-
Live unit testing4m 56s
-
Conclusion
-
Goodbye1m 1s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Expected exceptions