This two-day, instructor-led course provides students with the knowledge and skills to effectively use Visual Studio to design, write, and run high-quality unit tests. The course focuses on the applicable features and capabilities of Visual Studio as it relates to unit testing and Test-Driven Development (TDD). This course also introduces other, popular unit testing tools and techniques, and demonstrates how they integrate with Visual Studio and a team's development lifecycle.
Who should take this class?
This course is intended for current software development professionals who are involved with building high-quality .NET applications. Students will use Visual Studio while learning how to design, write, and run unit tests. They will also learn many relevant practices and techniques, such as TDD, refactoring, and how to test difficult code.
This course provide several learning objectives and benefits.
- Explain why unit tests are critical to software quality
- Differentiate unit tests and integration tests
- Describe the anatomy of a unit test and the 3A pattern (Arrange, Act, Assert)
- Use Assert, StringAssert, and CollectionAssert methods for testing
- Test for expected exceptions
- Use test class inheritance to improve readability and maintainability
- Explain why and how to test internal APIs
- Create and configure MSTest, NUnit, and xUnit test projects
- Use Test Explorer to manage and organize your tests
- Organize tests by project, namespace, class, state, duration, trait, or playlist
- Improve performance by running unit tests in parallel
- Run tests and manage test results
- View, group, and filter tests and test results
- Create and use a .runsettings file
- Enable continuous testing in Visual Studio
- Explain why Test-Driven Development (TDD) leads to better code design
- Practice TDD within Visual Studio
- Learn how to effectively refactor code, including legacy code, during TDD
- List practices for writing good unit tests
- Differentiate between happy path and sad path testing
- Test boundary conditions using the Right-BICEP practice
- Using naming conventions to organize tests and test assemblies
- Learn why and how to analyze code coverage
- Understand why code coverage should not be a metric
- Drive parameterized unit tests with data
- Test concurrently test using Live Unit Tests and NCrunch (3rd party)
- Test difficult code with the use of doubles such as dummies, fakes, stubs, and mocks
- Use Microsoft Fakes to test difficult code
- Use third-party mocking libraries, such as moq, to test difficult code
- Generate MSTest unit tests with IntelliTest
- Debug and profile unit test code
Module 1: Unit Testing in .NET
This module introduces the concept of unit testing and how it is supported by various unit testing frameworks.
- What is (and isn’t) a unit test
- Why write unit tests
- .NET unit testing frameworks
- MSTest, NUnit, xUnit
- The anatomy of a unit test
- Writing and running your first unit test
Module 2: Unit Testing in Visual Studio
This module introduces Visual Studio test projects, Test Explorer and other testing windows, and the practices for effectively writing, running, and managing unit tests and test results.
- Testing support in Visual Studio
- MSTest, NUnit, and xUnit test projects
- Test Explorer and other windows
- Writing and running unit tests in Visual Studio
- Managing a large number of tests and test results
- Organizing tests by grouping, filtering, and playlists
- Continuous testing in Visual Studio
Module 3: Test-Driven Development (TDD)
This module introduces Test Driven Development (TDD) and the business case for why you should practice it. Refactoring as well as a discussion of how to work with legacy code are also part of this module.
- TDD overview and benefits
- Practicing TDD within Visual Studio
- Effectively refactoring code
- Working with legacy code
- Using CodeLens to support TDD and refactoring
Module 4: Writing Good Unit Tests
Just knowing how to write unit tests and being disciplined in TDD is not enough. This module introduces other practices for ensuring that you write high-quality unit tests that cover more than just the happy path.
- Asking questions about your code
- Path testing (e.g. happy, sad, evil, etc.)
- Right BICEP testing
- Testing for expected exceptions
- Maintaining high-quality test code
- Unit test naming conventions (e.g. BDD)
- Organizing unit tests
Module 5: Leveraging Visual Studio
This module examines additional unit testing features found in Visual Studio, including code coverage, parameterized unit tests, and concurrent testing tools.
- Analyzing code coverage
- Using code coverage as a metric
- Data-driven (parameterized) unit tests
- DataRow, DynamicData, and DataSource attributes
- Concurrent testing using Live Unit Testing
- Concurrent testing using NCrunch
Module 6: Testing Difficult Code
This module introduces tools and techniques for testing difficult code, such as code with runtime dependencies.
- The need to isolate code under test
- Doubles (dummies, stubs, fakes, and mocks)
- Microsoft Fakes framework (stubs and shims)
- Comparing mocking frameworks
- Using moq .NET mocking framework
- Debugging and profiling slow-running unit tests
- Using IntelliTest with legacy code
Experience with writing, debugging, and maintaining code is recommended.
Experience with C#, unit testing, and Visual Studio are also helpful, but not required.