Test parameters

Keyboard Shortcuts

Writing a batch of unit test for testing a range of values can get tedious. This video looks at the concept of unit test parameters and how they can simplify testing ranges of values in a unit test. It also explains why the MsTest framework is not the best framework for working the test parameters.

- [Voiceover] Here's another situation…that appears when writing unit tests…that need to test a wide range of values.…In some cases you'll find yourself…creating dozens of tests to exercise…the code with the values.…I'll show you an example in this…NumberAnalyzer class.…On line 10, I have a constructor…that takes a CandidateNumber.…On line 13, I have a method…that returns a bool that's called…ContainsOddDigit.…The idea is, we'll look at the CandidateNumber.…If any of the digits are odd,…I'll return true.…

So if I pass the number 100, I'll get true.…If I pass the number 24, I'll get false.…To test this, I created a separate class,…CheckingForOddDigit_Should.…I compiled the project so…I could see my unit test.…I have seven tests.…As you noticed, the more tests you get,…the harder it is to find the test in here.…I do have good names for my tests…but it's getting harder to find them.…One thing you can do is go to your Test Explorer…and choose to group by the class name.…Now I see all the unit tests that are in.…

This CheckingForOddDigit_Should class.…

Resume Transcript Auto-Scroll

Author

Updated

8/29/2017

Released

6/16/2016

Ensure your code is up-to-par by performing a unit test, verifying your code works as expected. You can perform unit testing using Visual Studio 2015. Selecting a framework and creating a small piece of code, to exercise a specific area of functionality, is all you need to get started. In this course, learn about the types of frameworks, naming conventions, integrations, and options available to you and how to implement them into your testing workflow. Join Walt Ritscher as he explains the process and step-by-step instructions. Along the way, he provides guidance on how to test with multiple parameters, customize your test runs, discover untested code, and even debug the actual unit tests.

Topics include:

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

2h 48m

Duration

73,090

Views

Show MoreShow Less

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.