+ All Categories
Home > Documents > Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers.,...

Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers.,...

Date post: 09-Aug-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
11
Unit Testing using MOQ Framework © Meganadha Reddy K., 2014 http://www.netcomlearning.com/ Meganadha Reddy K. Technical Trainer | NetCom Learning www.NetComLearning.com
Transcript
Page 1: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Unit Testing using MOQ

Framework

© Meganadha Reddy K., 2014 http://www.netcomlearning.com/

Meganadha Reddy K. Technical Trainer | NetCom Learning

www.NetComLearning.com

Page 2: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Agenda

• Layered Architecture

• Unit Testing / Test Driven Development

• Why we need mocking

• Mocking Frameworks available

• Sample code using MOQ Framework

• Q & A

© Meganadha Reddy K., 2014 http://www.netcomlearning.com/

Page 3: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Layered Architecture

Most of the software projects will be designed as per below architecture

© Meganadha Reddy K., 2014 http://www.netcomlearning.com/

UI Layer Business

Logic Layer Data Access

Layer Database

Page 4: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Unit Testing (1 of 3)

© Meganadha Reddy K., 2014 http://www.netcomlearning.com/

UI Layer Business

Logic Layer Data Access

Layer Database

UI Layer

Test Methods

Business Logic Layer

Test Methods

Data Access Layer

Test Methods

Page 5: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Unit Testing (2 of 3)

© Meganadha Reddy K., 2014 http://www.netcomlearning.com/

UI Layer Business

Logic Layer Data Access

Layer Database

UI Layer

Test Methods

Business Logic Layer

Test Methods

Data Access Layer

Test Methods

Each layer will have its own Test Methods.

Page 6: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Unit Testing (3 of 3)

UI Layer Business

Logic Layer Data Access

Layer Database

UI Layer

Test Methods

Business Logic Layer

Test Methods

Data Access Layer

Test Methods

What happens when I run a test method for a method of Business Logic Layer?

Will the test method for BLL will call DAL method?

Page 7: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Why Mocking?

• Mocking is the framework using which you can mock a sub-sequent method

call.

• This is required as each layer will have their own test methods.

• Mocking will minimize the calls to sub-sequent layers., and there by stopping

to test an already tested method.

Are you confused here

Hmmm!!! Let me clarify again

Page 8: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Mocking Frameworks available

• Some of the mocking frameworks are:

• MOQ

• Rhino mock

• Type Mock

• FakeItEasy

• NMock3

Page 9: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Sample Code using MOQ framework

© Meganadha Reddy K., 2014 http://www.netcomlearning.com/

DEMO

Page 10: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Q & A

?

© Meganadha Reddy K., 2014 http://www.netcomlearning.com/

Page 11: Unit Testing using MOQ Framework€¦ · •Mocking will minimize the calls to sub-sequent layers., and there by stopping to test an already tested method. Are you confused here Hmmm!!!

Microsoft Authorized

Training Resources

• NetCom Learning is an innovative leader in IT, business and executive training to companies, individuals, and government agencies, dedicated to promoting the values of lifelong learning. NetCom Learning has trained over 80% of the Fortune 100 and helped advanced the skills of more than 71,000 professionals. Find out more: www.NetComLearning.com


Recommended