In this experiential webinar, our guest Mohamed Shaaban will share with you his wide experience in Unit Testing in addition to practical techniques for unit testing your code using C#, NUnit, and Moq.
2. Presented By &
Unit Testing in Action - C# NUnit, and Moq
XP Days xpdays.org is an initiative
for gathering people interested in
Agile, eXtreme Programming (aka:
XP), Scrum, Coding, etc.
XP is a lightweight, efficient, and low-
risk Agile Software Development
Framework intended to improve
software quality.
Agile Arena agilearena.net is an Agile
Consulting and Training company. specialized in
agile adoption and transformation for companies
and teams through:
• Designing their agile adoption programs
• Executing our programs and guiding the team
through their journey to sustainable agility .
• We also provide accredited training classes
for companies and individuals
4. Presented By &
AGENDA
• Unit Testing
• NUnit
• Moq
Unit Testing in Action - C# NUnit, and Moq
What we’ll be covering this webinar
5. Presented By &
What is automated testing?
• Automated testing is the practice of writing code to test our code, and then
run those tests in an automated fashion.
• Automated tests are repeatable
Unit Testing in Action - C# NUnit, and Moq
6. Presented By &
Why automated testing
• You can test our application code on a frequent basis and in less time.
• Catch bugs BEFORE deploying.
• Deploy with confidence.
• Refactor with confidence.
• Focus more on the quality.
* Refactoring means changing the structure of your code, without changing
its behavior.
Unit Testing in Action - C# NUnit, and Moq
7. Presented By &
Types of Automated Test
• Unit
• Test a unit of an application without its external dependencies.
• Cheap to write and fast to execute don’t give a lot of confidence.
• Integration
• Test the application with its dependencies.
• Take longer to execute and give more confidence.
• E2E
• Drives an application through its UI.
• Give you the greatest confidence and very slow and very brittle.
Unit Testing in Action - C# NUnit, and Moq
8. Presented By &
Testing framework
• NUnit
• MSTest
• xUnit
Unit Testing in Action - C# NUnit, and Moq
9. Presented By &
TDD
• With TDD you write your tests before writing the production code.
• Write a failing test.
• Write the simplest code to make the test pass.
• Refactor if necessary.
Unit Testing in Action - C# NUnit, and Moq
10. Presented By &
Benefits of TDD
• Testable source code.
• Full coverage by tests.
• Simpler implementation.
Unit Testing in Action - C# NUnit, and Moq
11. Presented By &
Good Unit Tests
• First class citizens.
• Clean , readable and maintainable.
• No logic.
• Isolated.
• Not too specific/general.
Unit Testing in Action - C# NUnit, and Moq
13. Presented By &
• Simple Unit Test
• Set Up and Tear Down
• Parameterized Tests
• Ignoring Tests
• Testing Strings
• Testing Arrays and Collections
• Testing the Return Type of Methods
• Testing Void Methods
• Testing Methods that Throw Exceptions
• Testing Methods that Raise an Event
• Testing Private Methods
Unit Testing in Action - C# NUnit, and Moq
NUnit Demo
14. Presented By &
• In software engineering, dependency injection is a technique whereby one
object (or static method) supplies the dependencies of another object. A
dependency is an object that can be used (a service).
Unit Testing in Action - C# NUnit, and Moq
DI
15. Presented By &
• Constructor Injection: In the constructor injection, the injector supplies the
service (dependency) through the client class constructor.
• Property Injection: In the property injection (aka the Setter Injection), the
injector supplies the dependency through a public property of the client
class.
• Method Injection: In this type of injection, the client class implements an
interface which declares the method(s) to supply the dependency and the
injector uses this interface to supply the dependency to the client class.
Unit Testing in Action - C# NUnit, and Moq
Types of dependency injection
16. Presented By &
• Moq
• NSubstitue
• FakeItEasy
• Rhino Mocks
Unit Testing in Action - C# NUnit, and Moq
Mocking Frameworks