Call Us: +32 2 466 00 16
Follow Us:

Effective Unit Testing

Training code
Book this course

Unit testing in .NET

What every developer wants: clean code that works. So how to you get your code to be maintainable and working? And even more important: keep your code working.

  • What every developer wants: Quality code that works; and keeps on working
  • Finding bugs: not just in code. - Or how NASA lost a 125.000.000$ Mars orbiter
  • What is unit testing? And what is a good unit test?
  • Understanding the difference between a unit test and an integration test
  • Test Driven Development - Should you be doing it?
  • Role-playing: Marge, Homer and Bart
  • The Triple-A of unit testing - and what has cooking to do with this?

Unit testing with Visual Studio

Visual Studio has Unit Testing built in with MSTest. So we will look at the unit-testing workflow with Visual Studio.

  • MSUnit - Built into Visual Studio
  • Building and running Unit Tests with MSUnit
  • Using the Test Explorer Window
  • Live unit testing with Visual Studio 2017

Using XUnit for writing Unit Tests

So why another unit testing framework? Xunit has been created with best practices in mind.

  • What is XUnit?
  • Unit Testing best practices with XUnit
  • Installing XUnit and its runner
  • Facts and Theories
  • Running tests in parallel

Writing testable code

If you want your code to be testable, you have to engineer your code for testing. You will learn about Stubs and Mocks, and how to replace dependencies that might interfere with testing.

  • Testing dependencies - and the art of writing testable code
  • The difference between a Stub and a Mock
  • How to replace dependencies with stub and mock objects
  • The Extract and Override pattern
  • Dependency injection
  • Testing database code
  • Replacing configuration in tests

Using MOQ

Building Stubs and Mocks can be a lot of work without an Isolation Framework. So here we look at MOQ, a framework that allows you to easily build the Fake objects you need for building great tests.

  • Understanding Isolation Frameworks
  • Building Stubs and Mocks with MOQ
  • Checking arguments and return values
  • Using Linq to Mocks

Using Microsoft Fakes

And how do you test 'untestable' code? Code where dependencies have been glued into the class you want to test? Then you need some magic: Microsoft Fakes. This product allows you to replace any class's implementation, making it easier to test legacy code and other difficult to test code.

  • What makes Microsoft Fakes so special
  • Testing legacy/untestable code
  • Building Stubs and Mocks with Fakes

Code Coverage

Have I tested enough? With code coverage you can see which paths in your code you have tested, and easily discovered untested conditional logic

  • How good are your tests?
  • Improving Code Coverage

Automatic Regression Testing

So your software works! Great! But how do you know if it will work next week, or next month? Did you break something adding some new cool feature? Test everyting again? Of course, but now we will make a machine do it automatically every time a team member makes a change.

  • What is a regression?
  • Using an automated build system
  • Continuous integration
  • Running integration tests
  • Automatic regression tests

SQL Unit Testing

And what about stored procedures? They might contain some very important business logic. SQL Unit testing from Database projects allows you to build a test project for your database code as well!

  • Database projects
  • Testing SQL with SQL Unit Testing

Acceptence testing with the Screenplay pattern.

The Screenplay Pattern is a user-centred model, which helps you shift the focus of automated acceptance tests from low-level interactions with the system to thinking about who the users of your system are, what is that they want to achieve by their interaction with your system and how exactly they're going to do it.

  • Building good automated acceptence tests
  • Actors, Abilities, Actions and Questions
  • Understanding the Screenplay pattern
  • Writing an acceptence test with the Screenplay pattern

Reproducing bugs with Intelli-Trace

Reproducing bugs that happened in production sometimes is very hard. Simply because the production machine is not the same machine a developer is using. Intelli-Trace is a Microsoft product that allows developers to quickly reproduce bugs found in production.

  • Reproducing bugs
  • Using Intelli-Trace to reproduce bugs
  • Post-mortem debugging with iTrace files

Writing solid, maintainable code that works. This is what every developer wants. This course teaches you the art of unit testing, where you learn to build testable code and various techniques to give your code a good spin. We will look at using unit test frameworks such as MSUnit and the very popular XUnit. Of course we will also look at using Stub and Mock objects, and we will use MOQ for this. Let's not forget some of the power tools such as Microsoft Fakes. Once you have your unit tests ready you will want to run them automatically, for example to do regression testing, using Continous Integration At the end of this course you will go home with a solid, practical understanding of unit testing and how to apply this in real life. U2U is known for is real-life approuch to training, so each chapter is accompanied with a hands-on lab.

This course is intended for experienced programmers who are very familiar with VB.NET or C# and have a working experience with the .NET Framework.

© 2018 U2U All rights reserved.