Unit Testing in C#
  • Unit testing in C#
  • Unit testing
    • What to test
    • When to test
    • Qualities of a good unit test suite
    • Qualities of a good unit test
    • Dealing with dependencies
    • Running the tests
  • NUnit
    • Quick glance at NUnit
    • Creating a NUnit test project
    • Anatomy of a test fixture
    • Lifecycle of a test fixture
    • Assertions
    • Asynchronous executions
    • Parameterized tests
    • Assumptions
    • Describing your tests
  • Moq
    • Quick glance at Moq
    • Method arguments
    • Method calls
    • Properties
    • Results
    • Callbacks
    • Exceptions
    • Events
    • Verifications
    • Base class
    • Mock customization
    • Implicit mocks
    • Mock repository
    • Custom matchers
    • Multiple interfaces
    • Protected members
    • Generic methods
    • Delegates
  • AutoFixture
    • Quick glance at AutoFixture
    • Fixture
    • Create and Build
    • Type customization
    • Data annotations
    • Default configurations
    • Building custom types
    • Relays
    • Tricks
    • Idioms
    • Integration with NUnit
    • Integration with Moq
    • Combining AutoFixture with NUnit and Moq
    • Extending AutoFixture
  • Advanced topics
    • Testing HttpClient
Powered by GitBook
On this page
  • The need for automated testing
  • Objectives of this course
  • Disclaimer
  • License

Was this helpful?

Unit testing in C#

The need for automated testing

Software systems are complex creatures. They are composed of many small components working together to accomplish a greater common goal.

Manually testing all the different use cases with all the possible parameters and making sure all the different expectations are respected would be impossible and quite a tedious job.

Therefore, having a proper suite of automated tests is extremely important for any non-trivial codebase.

It's important to emphasize the difference between the expectations we put on automated test suites. Unlike common knowledge would suggest, automated tests do not test whether the system is working correctly. Automated test suites codify the knowledge we have about the behavior of the system. A failing test doesn't represent a fault in the system. Instead, it represents a fault in our knowledge of the system's actual behavior. This is why development techniques such as Test-Driven Development (TDD) and Behavior-Driven Development (BDD) have grown in popularity in the recent years.

There are several types of automated tests. The most common ones are unit tests and integration tests.

Unit tests focus on the behavior of individual components by asserting the expected output given a known initial state and a known input.

As the name says, integration tests focus on the integration between multiple components by asserting the expected output of the collaboration of multiple components.

Objectives of this course

This course focuses on the creation of suites of unit tests aiming at asserting the known behavior of .NET components.

At the end of this course, you should have acquired the knowledge and be acquainted with the tools needed to author and execute unit tests targeting .NET services and components.

In this course we will be using NUnit, Moq and AutoFixture and learn how to glue them together to quickly create powerful test suites that clearly communicate their intent.

After having learned how to use these libraries, we will discuss some advanced scenarios like testing a service consuming a REST API.

Finally, we will look at what code coverage means and how we should look at this metric.

Disclaimer

License

NextWhat to test

Last updated 4 years ago

Was this helpful?

Part of the content of this guide is copied/inspired from created by and published with a .

This course is offered under a MIT license that can be consulted in the or at .

Unit Testing in C#
EMG - Educations Media Group AB
MIT license
GitHub repository
this address