Skip to Content
C# and .NET Core Test-Driven Development
book

C# and .NET Core Test-Driven Development

by Ayobami Adewole
May 2018
Intermediate to advanced content levelIntermediate to advanced
300 pages
7h 35m
English
Packt Publishing
Content preview from C# and .NET Core Test-Driven Development

xUnit.net shared test context

The test context setup is done in the test class constructor, since the test setup is not applicable in xUnit. For every test, xUnit creates a new instance of the test class, which implies that the codes in the class constructor are run for each test.

Oftentimes, it is desirable for unit test classes to share a test context because it can be expensive to create and clean up test contexts. xUnit offers three approaches to achieve this:

  • Constructor and dispose: Sharing setup or cleanup code without having to share the object instances
  • Class fixtures: Sharing object instances across tests in a single class
  • Collection fixtures: Sharing object instances across multiple test classes

You should use constructor and ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Design Patterns with C# and .NET Core

Hands-On Design Patterns with C# and .NET Core

Gaurav Aroraa, Jeffrey Chilberto
.NET Core in Action

.NET Core in Action

Dustin Metzgar

Publisher Resources

ISBN: 9781788292481Supplemental Content