Mocking Tool for easier unit testing

Slides:



Advertisements
Similar presentations
Telerik Software Academy HTML Basics.
Advertisements

Telerik Software Academy Software Quality Assurance Telerik Testing Framework.
Course Content, Evaluation, Exams
Database Course Program, Evaluation, Exams Telerik Software Academy Databases.
OOP Course Program, Evaluation, Exams, Resources Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Course Program, Evaluation and Exams Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Telerik Software Academy Software Quality Assurance.
Data-tier Application, Import, Refactoring, Publish, Schema Comparison, Database Unit Testing Borislav Statev Telerik Software Academy academy.telerik.com.
Course Content, Evaluation, Exams Telerik Software Academy ASP.NET Web Forms.
Creating and Running Your First C# Program Telerik Software Academy Telerik School Academy.
Planning and Tracking Software Quality.  What Is Software Quality?  Causes of Software Defects  What is Quality Assurance?  Improving the Software.
Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.
Test Roles and Independence of Testing Telerik Software Academy Software Quality Assurance.
Testing Web Services Unit Testing, Data Layer Testing, Web API Controllers Testing, Integration Testing Web Services & Cloud SoftUni Team testing Technical.
Course Program, Evaluation, Exams, Resources Telerik Software Academy Data structures and algorithms.
Private/Public fields, Module, Revealing Module Learning & Development Team Telerik Software Academy.
Steve Dower Software Engineer Python Tools for Visual Studio.
Database Course Program, Evaluation, Exams Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Test Driven Development Arrange, Act, Assert… Awesome Jason Offutt Software Engineer Central Christian Church
Course Program, Evaluation, Examination Telerik Software Academy Apps for Windows Phone & Windows Store.
JS Frameworks Course Program, Evaluation, Exams Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
Course Program, Evaluation and Exams Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
TEST-1 6. Testing & Refactoring. TEST-2 How we create classes? We think about what a class must do We focus on its implementation We write fields We write.
Course Program, Evaluation, Exams, Resources Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Telerik Software Academy Software Quality Assurance Binding business requirements to.NET code.
OOP Course Program, Evaluation, Exams, Resources Telerik Software Academy Object-Oriented Programming.
SOAP-based Web Services Telerik Software Academy Software Quality Assurance.
ASP.NET MVC Course Program, Evaluation, Exams Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
JS Course Program, Evaluation, Exams, Resources Telerik Software Academy JavaScript Fundamentals.
Course Program, Evaluation, Exams George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Reflection Programming under the hood SoftUni Team Technical Trainers Software University
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
Mocking with Moq Tools for Easier Unit Testing SoftUni Team Technical Trainers Software University
Mocking Unit Testing Methods with External Dependencies SoftUni Team Technical Trainers Software University
Mocking with Moq Mocking tools for easier unit testing Svetlin Nakov Technical Trainer Software University
LINQ and Lambda Expressions Telerik Software Academy LINQ Overview.
Mocking tools for easier unit testing Telerik Software Academy High Quality Code.
Course Program, Evaluation, Exams Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
S'n'D Course Program, Evaluation, Exams, Resources Doncho Minkov Telerik Software Academy academy.telerik.com Technical Trainer
Course Program, Evaluation, Exams George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Course Program, Evaluation, Examination Telerik Software Academy Hybrid Mobile Applications.
JS Course Program, Evaluation, Exams, Resources Doncho Minkov Telerik Software Academy academy.telerik.com Technical Trainer
Course Program, Evaluation, Examination Telerik Software Academy Mobile Applications for iPhone and iPad.
WPF Course Program, Evaluation, Exams Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
Web Services Course Program, Evaluation, Exams Telerik Software Academy Web Services and Cloud.
Kendo UI ASP.NET MVC Wrappers
JS Frameworks Course Program, Evaluation, Exams
Interface Segregation / Dependency Inversion
Redis and Redis with .NET
Introduction to .NET Florin Olariu
Setup QA Process Software Quality Assurance Telerik Software Academy
Mocking tools for easier unit testing
TESTING TEST DRIVEN DEVELOPMENT
Describe ways to assemble objects to implement a new functionality
JavaScript OOP: Course Introduction
Using ASP.NET Master Pages
Entity Framework Performance
JavaScript Applications: Course Introduction
Object-Oriented Programming: Course Intro
Kendo UI ASP.NET MVC Wrappers
ASP.NET MVC Introduction
Best Practices and Architecture
JavaScript Applications: Course Introduction
Best practices and architecture
Web Service Testing …in another way Software Quality Assurance
Building Rock-Solid Software
Unit Testing & Test-Driven Development for Mere Mortals
Designing For Testability
Setup QA Process Software Quality Assurance Telerik Software Academy
Dependency Injection Mechanism
Presentation transcript:

Mocking Tool for easier unit testing Mocking and JustMock Mocking Tool for easier unit testing Todor Totev Team Lead, MAT Team Todor.Totev@telerik.com Telerik Corp. http://telerik.com

How to write testable code Inverse of Control Pattern There is a decoupling of the execution of a certain task from implementation Every module can focus on what it is designed for Modules make no assumptions about what other systems do but rely on their contracts Replacing modules has no side effect on other modules More info at http://en.wikipedia.org/wiki/Inversion_of_control

Inverse of Control Public API should work with interfaces, not implementation classes (IEnumerable vs. List) BAD Code: GOOD Code: public Card[] Cards { get; private set; } public IList<ICard> Cards { get; private set; }

How to write testable code Dependency Injection MS Unity - http://unity.codeplex.com/ Consists of: a dependent consumer, a declaration of a component's dependencies, defined as interface contracts, an injector (sometimes referred to as a provider or container) that creates instances of classes that implement a given dependency interface on request.

How to write testable code BAD: public interface IViewBase {} public interface IPresenterBase {} public class MemoryLayoutView: IViewBase {} public class MemoryLayoutPresenter: IPresenterBase { private MemoryLayoutView view = new MemoryLayoutView(); public MemoryLayoutPresenter() { } }

How to write testable code Good: public interface IViewBase {} public interface IPresenterBase {} public class MemoryLayoutView: IViewBase {} public class MemoryLayoutPresenter : IPresenterBase { private IViewBase view; public MemoryLayoutPresenter(IViewBase myView) this.view = myView; } public class Program { static void Main() { InjectionContainer.Create<typeof(MemoryLayoutPresenter)>();

Why we use mocking Makes Unit Testing more effective Avoid writing boring boilerplate code

Why we use mocking Isolate dependencies among units

Why we use mocking Asserts expectations for code quality Ex: Checks that a method is called only once

Telerik JustMock Install from the Telerik account Use the Visual Studio add-in

Telerik JustMock Free version – excellent when the code is written with testability in mind Paid version –mocks everything (ex: mscorlib, EF, SQL), mocks legacy code base which is not written to be testable

JustMock Demo Sample: writing unit test by hand (without a mocking framework)

JustMock Demo The most often used APIs: .Occurence() .Returns() .DoInstead() .Throw() Arg.AnyInt Arg.Matches<type>(x => condition)

Mocking and JustMock http://academy.telerik.com

Free Trainings @ Telerik Academy C# Programming @ Telerik Academy csharpfundamentals.telerik.com Telerik Software Academy academy.telerik.com Telerik Academy @ Facebook facebook.com/TelerikAcademy Telerik Software Academy Forums forums.academy.telerik.com