8000 GitHub - ardalis/TestPatterns: Examples of approaches to unit testing different kinds of code in C#.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ardalis/TestPatterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test Patterns

Examples of approaches to unit testing different kinds of code in C#. These examples start with simple cases and move on to more complex patterns.

Give a Star! ⭐

If you like or are using this project to learn, please give it a star to help others find it. Thanks!

State-Based Testing

The simplest kinds of unit tests create collaborators, call methods, and inspect the results. These work best with public methods with non-void return signatures and no side effects.

Resources and Practice

Tests should follow SOLID principles, including Single Responsibility. Grouping tests by the method being tested helps achieve this. Read the following naming convention for a proven approach to organizing and naming your tests. Also, the FizzBuzz and String Calculator katas are great to use when first learning state-based testing.

Behavior-Based Testing (with Mocks)

When you can't evaluate whether a method did the right thing by looking at the state it returns or modifies publicly, another approach is to test the behavior of the method itself. This is often called "behavior-based" testing and frequently uses mock objects (or spies or fakes or other techniques) to capture behavior that took place within the method being tested. Collectively these different techniques are known as test doubles.

Resources and Practice

Testing Hard-To-Access State

Confirming the state of private or internal values when testing from another class and assembly can be a challenge. There are some patterns that can be used to overcome these challenges in most cases.

About

Examples of approaches to unit testing different kinds of code in C#.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0