There is a special type of unit test needed when dealing with unhandled exceptions in the system code. This tutorial shows how to use the ExpectedException attribute to properly assert that an exception should happen during a unit test.
- [Voiceover] There are times when your code…will throw an exception.…It could be because something went wrong.…Say your code forgot to check for a null value,…or it could be because your code…threw the exception deliberately to tell other developers…calling your API that they are doing it wrong.…Think about what this means when a unit tests…and counters an exception when running the test.…Should that be considered a failed test or not?…The default reaction in most unit testing frameworks…is to consider the test failed when an exception is thrown.…This is good if you didn't expect the exception,…because it means there is probably something wrong…with the test code or the app code.…
When you see the failed test you will investigate…and fix the problem.…Now let's consider the opposite,…when the code is supposed to throw the exception.…I have an example of that in my class commission calculator.…On line seven I have a method called…DetermineVariableRate.…On line eight I check to see…if the unit sold is less than zero. And if that's true,…
- 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 Intermediate
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.
1. Create a Simple Unit Test Framework
2. Unit Testing Conventions
Choose a naming convention5m 59s
3. Work with Visual Studio Unit Testing Framework
4. Work with xUnit
5. Work with nUnit
6. Additional Topics
- 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.Cancel
Take 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.