0% found this document useful (0 votes)
4 views19 pages

Testing C Code Slides

The document provides an overview of testing C# applications using debuggers and unit tests. It discusses the importance of debugging techniques, such as breakpoints and stepping through code, as well as the structure and advantages of unit tests. The document emphasizes that unit tests help identify bugs, improve code quality, and facilitate changes without fear of introducing new errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views19 pages

Testing C Code Slides

The document provides an overview of testing C# applications using debuggers and unit tests. It discusses the importance of debugging techniques, such as breakpoints and stepping through code, as well as the structure and advantages of unit tests. The document emphasizes that unit tests help identify bugs, improve code quality, and facilitate changes without fear of introducing new errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Testing C# Code

Gill Cleeren
CTO Xebia Microsoft Services Belgium

@gillcleeren
Overview
Testing your application using the
debugger
Writing a unit test
Testing Your Application Using the Debugger
Using the Debugger

Run in Debug mode

Breakpoints

Stepping through the code


Using Break Mode and Breakpoints
Debugger Commands

F5: start debugging F11: Step Into

F10: Step over Shift + F11: Step out


Demo

Using the debugger


Understanding the debugger windows
Writing a Unit Test
We aren’t perfect…
Introducing new bugs is easy!

We can try harnessing our code


using a unit test
Introducing Unit Tests

Code to test other code

Small components of the application

Validate value

Isolate part of the code


Advantages of Unit Tests

Find bugs Change without Improve quality Documentation


fear of breaking of the code
something
Creating a Unit Test Project
Sidestep: Adding a Reference
Structure of a Unit Test

Arrange Act Assert


Writing a Unit Test

public class EmployeeTests


{
[Fact]
public void PerformWork_Adds_DefaultNumberOfHours_IfNoValueSpecified()
{
//Arrange
Employee employee = new Employee(...);

//Act
employee.PerformWork();

//Assert
Assert.Equal(1, employee.NumberOfHoursWorked);
}
}
Running Tests with Test Explorer
Demo
Creating a unit test project
Adding a unit test
Running the test using Test Explorer
Summary
Using the debugger, we can test our code
and inspect values
Unit tests can help with making code more
resistant to errors being introduced
Up Next:

Working with files

You might also like